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:org.springframework.social.facebook.api.impl.json.StoryTagMapDeserializer.java

@SuppressWarnings("unchecked")
@Override//from w w  w . j a v  a  2  s. co  m
public Map<Integer, List<StoryTag>> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new FacebookModule());
    jp.setCodec(mapper);
    if (jp.hasCurrentToken()) {
        JsonNode dataNode = jp.readValueAs(JsonNode.class);
        if (dataNode != null) {
            return (Map<Integer, List<StoryTag>>) mapper
                    .reader(new TypeReference<Map<Integer, List<StoryTag>>>() {
                    }).readValue(dataNode);
        }
    }

    return Collections.emptyMap();
}

From source file:things.thing.ThingListDeserializer.java

@Override
public ThingList deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    List<Thing> things = objectMapper.readValue(jp, new TypeReference<List<Thing>>() {
    });//from  www . java  2  s .co  m

    return new ThingList(things);
}

From source file:com.vmware.photon.controller.client.resource.DeploymentApi.java

/**
 * List all deployments.//from  www .j a v  a2 s . co  m
 *
 * @return List of flavors
 * @throws IOException
 */
public ResourceList<Deployment> listAll() throws IOException {
    HttpResponse httpResponse = this.restClient.perform(RestClient.Method.GET, getBasePath(), null);
    this.restClient.checkResponse(httpResponse, HttpStatus.SC_OK);

    return this.restClient.parseHttpResponse(httpResponse, new TypeReference<ResourceList<Deployment>>() {
    });
}

From source file:com.evrythng.java.wrapper.service.BatchService.java

/**
 * Creates a new {@link Batch}./*from w w  w. jav  a 2  s.  com*/
 * <p>
 * POST {@value #PATH_BATCHES}
 *
 * @param batch the instance holding the {@link Batch} resource data
 * @return a preconfigured {@link Builder}
 */
public Builder<Batch> batchCreator(final Batch batch) throws EvrythngClientException {

    return post(PATH_BATCHES, batch, new TypeReference<Batch>() {

    });
}

From source file:feign.ranger.client.ServiceDiscoveryClient.java

@Builder
ServiceDiscoveryClient(String namespace, String serviceName, String environment, ObjectMapper objectMapper,
        CuratorFramework curator) throws Exception {
    this.criteria = ShardInfo.builder().environment(environment).build();
    this.serviceFinder = ServiceFinderBuilders.<ShardInfo>shardedFinderBuilder().withCuratorFramework(curator)
            .withNamespace(namespace).withServiceName(serviceName).withDeserializer(data -> {
                try {
                    return objectMapper.readValue(data, new TypeReference<ServiceNode<ShardInfo>>() {
                    });//ww w .ja v a  2  s  .c  o m
                } catch (Exception e) {
                    log.warn("Could not parse node data", e);
                }
                return null;
            }).build();
}

From source file:org.springframework.cloud.config.monitor.CompositePropertyPathNotificationExtractorTests.java

@Test
public void githubSample() throws Exception {
    // See https://developer.github.com/v3/activity/events/types/#pushevent
    Map<String, Object> value = new ObjectMapper().readValue(
            new ClassPathResource("github.json").getInputStream(), new TypeReference<Map<String, Object>>() {
            });//from   ww  w .j  a  va2s . c  o  m
    this.headers.set("X-Github-Event", "push");
    PropertyPathNotification extracted = this.extractor.extract(this.headers, value);
    assertNotNull(extracted);
    assertEquals("README.md", extracted.getPaths()[0]);
}

From source file:com.meltmedia.dropwizard.etcd.example.HelloProcessor.java

@Override
public void start() throws Exception {
    // This line wires up the processing and creates a service for managing processes.
    processService = service.get().newProcessService(HELLO_DIRECTORY, HelloProcess::new,
            new TypeReference<HelloProcessConfig>() {
            });/*from   w  w w  .  j  a  va 2s.  co m*/

    processService.start();
}

From source file:org.springframework.social.facebook.api.impl.json.QuestionOptionListDeserializer.java

@SuppressWarnings("unchecked")
@Override//w  w  w.  j av a 2s. c  o m
public List<QuestionOption> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new FacebookModule());
    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:org.springframework.social.facebook.api.impl.json.MessageTagMapDeserializer.java

@SuppressWarnings("unchecked")
@Override//from  ww w  .j  a v a 2  s  . c  o  m
public Map<Integer, List<MessageTag>> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new FacebookModule());
    jp.setCodec(mapper);
    if (jp.hasCurrentToken()) {
        JsonNode dataNode = jp.readValueAs(JsonNode.class);
        if (dataNode != null) {
            return (Map<Integer, List<MessageTag>>) mapper
                    .reader(new TypeReference<Map<Integer, List<MessageTag>>>() {
                    }).readValue(dataNode);
        }
    }

    return Collections.emptyMap();
}

From source file:com.basistech.rosette.dm.json.array.MorphoListTest.java

@Test
public void oneMorphoAnalysis() throws Exception {
    MorphoAnalysis ma = new MorphoAnalysis.Builder().lemma("plainLemma").build();
    String json = objectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(ma);
    System.out.println(json);/*from   w w w  .j  a v a2 s  .com*/
    MorphoAnalysis readBack = objectMapper().readValue(json, MorphoAnalysis.class);
    assertEquals(ma, readBack);

    // an uncustomized itemList ...
    List<MorphoAnalysis> list = Lists.newArrayList(ma);
    json = objectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(list);
    System.out.println(json);
    List<MorphoAnalysis> readBackList = objectMapper().readValue(json,
            new TypeReference<List<MorphoAnalysis>>() {
            });
    assertEquals(list, readBackList);
}