Example usage for com.fasterxml.jackson.core JsonParser hasCurrentToken

List of usage examples for com.fasterxml.jackson.core JsonParser hasCurrentToken

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonParser hasCurrentToken.

Prototype

public abstract boolean hasCurrentToken();

Source Link

Document

Method for checking whether parser currently points to a token (and data for that token is available).

Usage

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);/*w  w w.  j a  v a2s .c  om*/
    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.facebook.api.impl.json.TagListDeserializer.java

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

    return null;
}

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

public List<Recommendation> deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new LinkedInModule());
    jp.setCodec(mapper);// w  w w  . ja  v a2 s  . c o  m
    if (jp.hasCurrentToken()) {
        JsonNode dataNode = jp.readValueAs(JsonNode.class).get("values");
        if (dataNode != null) {
            return mapper.reader(new TypeReference<List<Recommendation>>() {
            }).readValue(dataNode);
        }
    }
    return null;
}

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

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

    return Collections.emptyList();
}

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

@SuppressWarnings("unchecked")
@Override//w w  w.  j  a  va  2 s  .  co 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 w ww .ja  va2s .com
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:org.springframework.social.facebook.api.impl.json.StoryTagMapDeserializer.java

@SuppressWarnings("unchecked")
@Override/*  ww w  .  ja  v  a2s .  c  o 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: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);/*from w w  w  .  j av a  2  s . com*/
    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.facebook.api.impl.json.CommentListAndCountDeserializer.java

@SuppressWarnings("unchecked")
@Override/*from w  ww .j  a va2  s .  c  om*/
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.springframework.social.facebook.api.impl.json.ReferenceListAndCountDeserializer.java

@SuppressWarnings("unchecked")
@Override/*from  w  w w  .  j av a  2 s  . co m*/
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;
}