Example usage for com.fasterxml.jackson.databind ObjectMapper reader

List of usage examples for com.fasterxml.jackson.databind ObjectMapper reader

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper reader.

Prototype

public ObjectReader reader(ContextAttributes attrs) 

Source Link

Document

Factory method for constructing ObjectReader that will use specified default attributes.

Usage

From source file:com.vsct.dt.hesperides.indexation.search.ApplicationSearch.java

/**
 * Main constructor.// w ww .ja  v a2s. com
 *
 * @param elasticSearchClient
 */
public ApplicationSearch(final ElasticSearchClient elasticSearchClient) {
    ObjectMapper objectMapper = Jackson.newObjectMapper();
    JavaType searchType = objectMapper.getTypeFactory().constructParametricType(ElasticSearchResponse.class,
            ApplicationSearchResponse.class);
    this.elasticSearchVsctApplicationReader = objectMapper.reader(searchType);
    JavaType searchTypePlatform = objectMapper.getTypeFactory()
            .constructParametricType(ElasticSearchResponse.class, PlatformSearchResponse.class);
    this.elasticSearchVsctPlatformReader = objectMapper.reader(searchTypePlatform);
    JavaType searchTypePlatformApplication = objectMapper.getTypeFactory()
            .constructParametricType(ElasticSearchResponse.class, PlatformApplicationSearchResponse.class);
    this.elasticSearchVsctPlatformApplicationReader = objectMapper.reader(searchTypePlatformApplication);
    this.elasticSearchClient = elasticSearchClient;
}

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

@SuppressWarnings("unchecked")
@Override/*w  ww.ja va  2  s  .  c  om*/
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.ReferenceListAndCountDeserializer.java

@SuppressWarnings("unchecked")
@Override/* w w  w.j av  a 2s  .  c  om*/
public ListAndCount<Reference> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new FacebookModule());
    jp.setCodec(mapper);
    if (jp.hasCurrentToken()) {
        JsonNode node = jp.readValueAs(JsonNode.class);
        JsonNode dataNode = node.get("data");
        List<Reference> commentsList = dataNode != null
                ? (List<Reference>) mapper.reader(new TypeReference<List<Reference>>() {
                }).readValue(dataNode)
                : Collections.<Reference>emptyList();
        JsonNode countNode = node.get("count");
        int referenceCount = countNode != null ? countNode.intValue() : 0;
        return new ListAndCount<Reference>(commentsList, referenceCount);
    }

    return null;
}

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

@SuppressWarnings("unchecked")
@Override/* w ww .  jav a  2 s  .  co m*/
public ListAndCount<Comment> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new FacebookModule());
    jp.setCodec(mapper);
    if (jp.hasCurrentToken()) {
        JsonNode commentsNode = jp.readValueAs(JsonNode.class);
        JsonNode dataNode = commentsNode.get("data");
        List<Comment> commentsList = dataNode != null
                ? (List<Comment>) mapper.reader(new TypeReference<List<Comment>>() {
                }).readValue(dataNode)
                : Collections.<Comment>emptyList();
        JsonNode countNode = commentsNode.get("count");
        int commentCount = countNode != null ? countNode.intValue() : 0;
        return new ListAndCount<Comment>(commentsList, commentCount);
    }

    return null;
}

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  w w  w. j av  a2  s  . c o  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:org.springframework.social.twitter.api.impl.SimilarPlacesDeserializer.java

@Override
public SimilarPlacesResponse deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new TwitterModule());
    jp.setCodec(mapper);//from w ww. 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:io.fabric8.mq.controller.coordination.ReplicationControllerTest.java

@Test
public void testCreateReplicationController() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    /*//from   ww  w  . ja v a2  s. com
    String basedir = System.getProperty("basedir", "apps/fabric8-mq-controller");
    String fileName = basedir + "/src/main/resources/replication-template.json";
    */

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    URL url = classLoader.getResource("META-INF/replicator-template.json");

    ReplicationController result = mapper.reader(ReplicationController.class).readValue(url);

    Assert.assertNotNull(result);
}

From source file:io.fabric8.mq.coordination.ReplicationControllerTest.java

@Test
public void testCreateReplicationController() throws Exception {
    ObjectMapper mapper = KubernetesFactory.createObjectMapper();
    /*//from w ww  .j a va2  s  .c  o m
    String basedir = System.getProperty("basedir", "apps/fabric8-mq-controller");
    String fileName = basedir + "/src/main/resources/replication-template.json";
    */

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    URL url = classLoader.getResource("META-INF/replicator-template.json");

    ReplicationController result = mapper.reader(ReplicationController.class).readValue(url);

    Assert.assertNotNull(result);
}

From source file:org.agorava.linkedin.jackson.LikesListDeserializer.java

@Override
public List<LinkedInProfile> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = BeanResolver.getInstance().resolve(ObjectMapper.class);
    jp.setCodec(mapper);/*from  w w  w  . ja v  a  2 s  .co m*/
    if (jp.hasCurrentToken()) {
        JsonNode dataNode = jp.readValueAs(JsonNode.class).get("values");
        List<LinkedInProfile> likes = new ArrayList<LinkedInProfile>();
        // Have to iterate through list due to person sub object.
        for (JsonNode like : dataNode) {
            LinkedInProfile profile = mapper.reader(new TypeReference<LinkedInProfile>() {
            }).readValue(like.get("person"));
            likes.add(profile);
        }
        return likes;
    }

    return null;
}

From source file:org.springframework.social.linkedin.api.impl.json.LikesListDeserializer.java

@Override
public List<LinkedInProfile> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new LinkedInModule());
    jp.setCodec(mapper);/*w w w .j  a  v  a  2  s.  c  o m*/
    if (jp.hasCurrentToken()) {
        JsonNode dataNode = jp.readValueAs(JsonNode.class).get("values");
        List<LinkedInProfile> likes = new ArrayList<LinkedInProfile>();
        // Have to iterate through list due to person sub object.
        for (JsonNode like : dataNode) {
            LinkedInProfile profile = mapper.reader(new TypeReference<LinkedInProfile>() {
            }).readValue(like.get("person"));
            likes.add(profile);
        }
        return likes;
    }

    return null;
}