Example usage for com.fasterxml.jackson.core.type TypeReference TypeReference

List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core.type TypeReference TypeReference.

Prototype

protected TypeReference() 

Source Link

Usage

From source file:uk.co.sdev.async.http.CompositionTest.java

private CompletableFuture<List<Offer>> offers(Profile profile) {
    return completableFutureClient.get(
            "http://localhost:9101/offers/" + profile.getSpending().name().toLowerCase(),
            new TypeReference<List<Offer>>() {
            });//from  w w w .  j a va 2  s .  c  o  m
}

From source file:com.github.nmorel.gwtjackson.jackson.annotations.JsonRawValueJacksonTest.java

@Test
public void testJsonString() {
    JsonRawValueTester.INSTANCE.testJsonString(createMapper(new TypeReference<ClassWithJsonAsString>() {
    }));
}

From source file:org.agorava.facebook.jackson.QuestionOptionListDeserializer.java

@SuppressWarnings("unchecked")
@Override/*ww w. ja va  2 s .  c o m*/
public List<QuestionOption> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = BeanResolver.getInstance().resolve(ObjectMapper.class);
    jp.setCodec(mapper);
    if (jp.hasCurrentToken()) {
        TreeNode dataNode = jp.readValueAs(JsonNode.class).get("data");
        if (dataNode != null) {
            // TODO: THIS PROBABLY ISN"T RIGHT
            return (List<QuestionOption>) mapper.reader(new TypeReference<List<QuestionOption>>() {
            }).readValue((JsonNode) dataNode);
        }
    }

    return null;
}

From source file:fr.pilato.elasticsearch.crawler.fs.client.JsonUtil.java

public static Map<String, Object> asMap(InputStream stream) {
    try {/*from   w w  w.jav a  2s.c  o  m*/
        return getMapper().readValue(stream, new TypeReference<Map<String, Object>>() {
        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.surfs.storage.block.service.impl.ExportServiceImpl.java

@Override
public List<ExportInfo> getExportInfos() {
    List<ExportInfo> list = new ArrayList<>();
    ObjectMapper objectMapper = new ObjectMapper();

    try {/*  w  w w. ja v  a  2  s.  c  o m*/
        // local
        String jsonLocal = CmdUtils.executeCmdForString(BlockConstant.BLOCK_TARGET_PATH);
        if (!StringUtils.isBlank(jsonLocal)) {
            ExportInfo infoLocal = objectMapper.readValue(jsonLocal, new TypeReference<ExportInfo>() {
            });
            LogFactory.info(jsonLocal);
            list.add(infoLocal);
        }

        // remote
        String jsonRemote = getRemoteExportInfoJson();
        if (!StringUtils.isBlank(jsonRemote)) {
            ExportInfo infoRemote = objectMapper.readValue(jsonRemote, new TypeReference<ExportInfo>() {
            });
            LogFactory.info(jsonRemote);
            list.add(infoRemote);
        }
    } catch (Exception e) {
        LogFactory.trace("call getExportInfos error", e);
    }
    return list;
}

From source file:hola.ControladorUsuario.java

@RequestMapping(value = "/usuario", method = RequestMethod.PUT, headers = { "Accept=application/json" })
@ResponseBody// w  ww.  j  a  v  a  2s  .c om
String actualizar(@RequestBody String json) throws Exception {
    System.out.println("<<<<<<<<<Se ha recibido el json" + json);
    Map<String, String> map = new HashMap<String, String>();
    ObjectMapper mapper = new ObjectMapper();

    //Transformamos el json
    map = mapper.readValue(json, new TypeReference<HashMap<String, String>>() {
    });
    int edad = Integer.parseInt(map.get("edad"));
    float sueldo = Float.parseFloat(map.get("sueldo"));
    int id = Integer.parseInt(map.get("idUsuario"));

    String nombre = map.get("nombre");
    //AJUSTAMOS los campos veniudos de JSON al objeto a guardarse  
    Usuario u = new Usuario();
    u.setEdad(edad);
    u.setNombre(nombre);
    u.setSueldo(sueldo);
    u.setIdUsuario(id);
    //Guardamos el objeto
    DAOUsuario dao = new DAOUsuario();
    dao.actualizar(u);

    return "Se actualizo el usuario  " + nombre;
}

From source file:com.netflix.edda.EddaElasticLoadBalancingClient.java

public DescribeInstanceHealthResult describeInstanceHealth(DescribeInstanceHealthRequest request) {
    validateNotEmpty("LoadBalancerName", request.getLoadBalancerName());

    TypeReference<InstanceStateView> ref = new TypeReference<InstanceStateView>() {
    };// w ww  . j  a  va2s.  c om
    String loadBalancerName = request.getLoadBalancerName();

    String url = config.url() + "/api/v2/view/loadBalancerInstances/" + loadBalancerName + ";_expand";
    try {
        InstanceStateView instanceStateView = parse(ref, doGet(url));
        List<InstanceState> instanceStates = instanceStateView.getInstances();

        List<Instance> instances = request.getInstances();
        List<String> ids = new ArrayList<String>();
        if (instances != null) {
            for (Instance i : instances)
                ids.add(i.getInstanceId());
        }
        if (shouldFilter(ids)) {
            List<InstanceState> iss = new ArrayList<InstanceState>();
            for (InstanceState is : instanceStates) {
                if (matches(ids, is.getInstanceId()))
                    iss.add(is);
            }
            instanceStates = iss;
        }

        return new DescribeInstanceHealthResult().withInstanceStates(instanceStateView.getInstances());
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

From source file:org.agorava.twitter.jackson.SimilarPlacesDeserializer.java

@Override
public SimilarPlacesResponse deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = BeanResolver.getInstance().resolve(ObjectMapper.class);
    jp.setCodec(mapper);/*from ww w . j a v  a 2  s.  co m*/
    JsonNode node = jp.readValueAs(JsonNode.class);
    JsonNode resultNode = node.get("result");
    String token = resultNode.get("token").textValue();
    JsonNode placesNode = resultNode.get("places");
    @SuppressWarnings("unchecked")
    List<Place> places = (List<Place>) mapper.reader(new TypeReference<List<Place>>() {
    }).readValue(placesNode);
    return new SimilarPlacesResponse(places, token);
}

From source file:com.vsct.dt.strowgr.admin.repository.consul.ConsulItem.java

T value(ObjectMapper mapper) {
    try {/*from   w  w  w.j  av  a 2  s . c  o m*/
        return mapper.readValue(Base64.getDecoder().decode(value), new TypeReference<T>() {
        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:wercker4j.response.ResponseWrapper.java

public List<BuildSummary> builds() throws Wercker4jException {
    ObjectMapper objectMapper = new ObjectMapper();
    try {//from   w w  w.  j  ava2 s  .c  o m
        return objectMapper.readValue(response, new TypeReference<List<BuildSummary>>() {
        });
    } catch (Exception e) {
        throw new Wercker4jException(e);
    }
}