// Path: agorava-facebook-api/src/main/java/org/agorava/facebook/model/Comment.java
// public class Comment implements Identifiable {
//     /**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = -4328142297172795693L;
// 
// 	private final String id;
// 
//     private final String message;
// 
//     private final Date createdTime;
// 
//     private final Reference from;
// 
//     private List<Reference> likes;
// 
//     private int likesCount;
// 
//     /**
//      * Constructs a Comment object.
//      *
//      * @param id          the comment's Graph API ID
//      * @param from        the author of the comment
//      * @param message     the comment text
//      * @param createdTime the creation time of the comment
//      */
//     public Comment(String id, Reference from, String message, Date createdTime) {
//         this.id = id;
//         this.from = from;
//         this.message = message;
//         this.createdTime = createdTime;
//     }
// 
//     /**
//      * The comment's Graph API object ID
//      */
//     public String getId() {
//         return id;
//     }
// 
//     /**
//      * The text of the comment
//      */
//     public String getMessage() {
//         return message;
//     }
// 
//     /**
//      * The time the comment was created.
//      */
//     public Date getCreatedTime() {
//         return createdTime;
//     }
// 
//     /**
//      * A reference to the user who posted the comment.
//      */
//     public Reference getFrom() {
//         return from;
//     }
// 
//     /**
//      * A list of references to users who liked this comment.
//      * May be null, as Facebook often sends only a count of likes.
//      * In some cases (such as a comment on a checkin) the likes will be a list of references.
//      */
//     public List<Reference> getLikes() {
//         return likes;
//     }
// 
//     /**
//      * The number of users who like this comment.
//      */
//     public int getLikesCount() {
//         return likesCount;
//     }
// }
// 
// Path: agorava-facebook-api/src/main/java/org/agorava/facebook/model/ListAndCount.java
// public class ListAndCount<T> {
// 
//     private final List<T> list;
// 
//     private final int count;
// 
//     public ListAndCount(List<T> list, int count) {
//         this.list = list;
//         this.count = count;
//     }
// 
//     public int getCount() {
//         return count;
//     }
// 
//     public List<T> getList() {
//         return list;
//     }
// 
// }


import static org.agorava.api.atinject.BeanResolver.getInstance;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.agorava.facebook.model.Comment;
import org.agorava.facebook.model.ListAndCount;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
/*
 * Copyright 2013 Agorava
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package org.agorava.facebook.jackson;




class CommentListAndCountDeserializer extends JsonDeserializer<ListAndCount<Comment>> {

    @SuppressWarnings("unchecked")
    @Override
    public ListAndCount<Comment> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
            JsonProcessingException {
        ObjectMapper mapper = getInstance().resolve(ObjectMapper.class);
        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();
// Path: agorava-facebook-api/src/main/java/org/agorava/facebook/model/Comment.java
// public class Comment implements Identifiable {
//     /**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = -4328142297172795693L;
// 
// 	private final String id;
// 
//     private final String message;
// 
//     private final Date createdTime;
// 
//     private final Reference from;
// 
//     private List<Reference> likes;
// 
//     private int likesCount;
// 
//     /**
//      * Constructs a Comment object.
//      *
//      * @param id          the comment's Graph API ID
//      * @param from        the author of the comment
//      * @param message     the comment text
//      * @param createdTime the creation time of the comment
//      */
//     public Comment(String id, Reference from, String message, Date createdTime) {
//         this.id = id;
//         this.from = from;
//         this.message = message;
//         this.createdTime = createdTime;
//     }
// 
//     /**
//      * The comment's Graph API object ID
//      */
//     public String getId() {
//         return id;
//     }
// 
//     /**
//      * The text of the comment
//      */
//     public String getMessage() {
//         return message;
//     }
// 
//     /**
//      * The time the comment was created.
//      */
//     public Date getCreatedTime() {
//         return createdTime;
//     }
// 
//     /**
//      * A reference to the user who posted the comment.
//      */
//     public Reference getFrom() {
//         return from;
//     }
// 
//     /**
//      * A list of references to users who liked this comment.
//      * May be null, as Facebook often sends only a count of likes.
//      * In some cases (such as a comment on a checkin) the likes will be a list of references.
//      */
//     public List<Reference> getLikes() {
//         return likes;
//     }
// 
//     /**
//      * The number of users who like this comment.
//      */
//     public int getLikesCount() {
//         return likesCount;
//     }
// }
// 
// Path: agorava-facebook-api/src/main/java/org/agorava/facebook/model/ListAndCount.java
// public class ListAndCount<T> {
// 
//     private final List<T> list;
// 
//     private final int count;
// 
//     public ListAndCount(List<T> list, int count) {
//         this.list = list;
//         this.count = count;
//     }
// 
//     public int getCount() {
//         return count;
//     }
// 
//     public List<T> getList() {
//         return list;
//     }
// 
// }


// Path: agorava-facebook-cdi/src/main/java/org/agorava/facebook/jackson/CommentListAndCountDeserializer.java
import static org.agorava.api.atinject.BeanResolver.getInstance;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.agorava.facebook.model.Comment;
import org.agorava.facebook.model.ListAndCount;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

/*
 * Copyright 2013 Agorava
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package org.agorava.facebook.jackson;




class CommentListAndCountDeserializer extends JsonDeserializer<ListAndCount<Comment>> {

    @SuppressWarnings("unchecked")
    @Override
    public ListAndCount<Comment> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
            JsonProcessingException {
        ObjectMapper mapper = getInstance().resolve(ObjectMapper.class);
        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();
            return new ListAndCount<Comment>(commentsList, commentsList.size());