// Path: src/main/java/net/vz/mongodb/jackson/DBRef.java
// public class DBRef<T, K> {
//     private final K id;
//     private final String collectionName;
// 
//     /**
//      * Construct a new database reference with the given id and collection name
//      *
//      * @param id             The id of the database reference to construct
//      * @param collectionName The name of the collection
//      */
//     public DBRef(K id, String collectionName) {
//         this.id = id;
//         this.collectionName = collectionName;
//     }
// 
//     /**
//      * Construct a new database reference with the given id and type.  The type must be annotated with
//      * {@link MongoCollection}, so that the name can be worked out.
//      *
//      * @param id             The id of the database reference to construct
//      * @param type           The type of the object
//      * @throws MongoJsonMappingException If no MongoCollection annotation is found on the type
//      */
//     public DBRef(K id, Class<T> type) throws MongoJsonMappingException {
//         this.id = id;
//         MongoCollection collection = type.getAnnotation(MongoCollection.class);
//         if (collection == null) {
//             throw new MongoJsonMappingException("Only types that have the @MongoCollection annotation on them can be used with this constructor");
//         }
//         this.collectionName = collection.name();
//     }
// 
//     /**
//      * Get the ID of this object
//      *
//      * @return The ID of this object
//      */
//     public K getId() {
//         return id;
//     }
// 
//     /**
//      * Get the name of the collection this object lives in
//      *
//      * @return The name of the collection this object lives in
//      */
//     public String getCollectionName() {
//         return collectionName;
//     }
// 
//     /**
//      * Fetch the object.  Should only be called for references that have been returned by the mapper, will return null
//      * otherwise.
//      * <p/>
//      * Deserialisation is done by the ObjectMapper that fetched the object that this reference belongs to.
//      *
//      * @return If this DBRef was returned by the mapper, the referenced object, if it exists, or null
//      */
//     public T fetch() {
//         return null;
//     }
// 
//     /**
//      * Fetch only the given fields of the object.  Should only be called for references that have been returned by the
//      * mapper, will return null otherwise.
//      * <p/>
//      * Deserialisation is done by the ObjectMapper that fetched the object that this reference belongs to.
//      * <p/>
//      * Unlike the <code>fetch()</code> method, calls to this are not cached.
//      *
//      * @param fields The fields to fetch
//      * @return If this DBRef was returned by the mapper, the referenced object, if it exists, or null
//      */
//     public T fetch(DBObject fields) {
//         return null;
//     }
// }


import net.vz.mongodb.jackson.DBRef;
import org.codehaus.jackson.map.BeanDescription;
import org.codehaus.jackson.map.BeanProperty;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.DeserializerProvider;
import org.codehaus.jackson.map.JsonDeserializer;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.module.SimpleDeserializers;
import org.codehaus.jackson.type.JavaType;
import java.util.Calendar;
import java.util.Date;
/*
 * Copyright 2011 VZ Netzwerke Ltd
 *
 * 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 net.vz.mongodb.jackson.internal;



/**
 * Deserializers for Mongo Jackson Mapper
 *
 * @author James Roper
 * @since 1.2
 */
public class MongoJacksonDeserializers extends SimpleDeserializers {
    public MongoJacksonDeserializers() {
        addDeserializer(Date.class, new DateDeserializer());
        addDeserializer(Calendar.class, new CalendarDeserializer());
    }

    public JsonDeserializer<?> findBeanDeserializer(JavaType type, DeserializationConfig config, DeserializerProvider provider, BeanDescription beanDesc, BeanProperty property) throws JsonMappingException {
        if (type.getRawClass() == DBRef.class) {
            if (!type.hasGenericTypes()) {
                throw new JsonMappingException("Property " + property + " doesn't declare object and key type");
            }
            JavaType objectType = type.containedType(0);
            JavaType keyType = type.containedType(1);
            return new DBRefDeserializer(objectType, keyType);
        }
// Path: src/main/java/net/vz/mongodb/jackson/DBRef.java
// public class DBRef<T, K> {
//     private final K id;
//     private final String collectionName;
// 
//     /**
//      * Construct a new database reference with the given id and collection name
//      *
//      * @param id             The id of the database reference to construct
//      * @param collectionName The name of the collection
//      */
//     public DBRef(K id, String collectionName) {
//         this.id = id;
//         this.collectionName = collectionName;
//     }
// 
//     /**
//      * Construct a new database reference with the given id and type.  The type must be annotated with
//      * {@link MongoCollection}, so that the name can be worked out.
//      *
//      * @param id             The id of the database reference to construct
//      * @param type           The type of the object
//      * @throws MongoJsonMappingException If no MongoCollection annotation is found on the type
//      */
//     public DBRef(K id, Class<T> type) throws MongoJsonMappingException {
//         this.id = id;
//         MongoCollection collection = type.getAnnotation(MongoCollection.class);
//         if (collection == null) {
//             throw new MongoJsonMappingException("Only types that have the @MongoCollection annotation on them can be used with this constructor");
//         }
//         this.collectionName = collection.name();
//     }
// 
//     /**
//      * Get the ID of this object
//      *
//      * @return The ID of this object
//      */
//     public K getId() {
//         return id;
//     }
// 
//     /**
//      * Get the name of the collection this object lives in
//      *
//      * @return The name of the collection this object lives in
//      */
//     public String getCollectionName() {
//         return collectionName;
//     }
// 
//     /**
//      * Fetch the object.  Should only be called for references that have been returned by the mapper, will return null
//      * otherwise.
//      * <p/>
//      * Deserialisation is done by the ObjectMapper that fetched the object that this reference belongs to.
//      *
//      * @return If this DBRef was returned by the mapper, the referenced object, if it exists, or null
//      */
//     public T fetch() {
//         return null;
//     }
// 
//     /**
//      * Fetch only the given fields of the object.  Should only be called for references that have been returned by the
//      * mapper, will return null otherwise.
//      * <p/>
//      * Deserialisation is done by the ObjectMapper that fetched the object that this reference belongs to.
//      * <p/>
//      * Unlike the <code>fetch()</code> method, calls to this are not cached.
//      *
//      * @param fields The fields to fetch
//      * @return If this DBRef was returned by the mapper, the referenced object, if it exists, or null
//      */
//     public T fetch(DBObject fields) {
//         return null;
//     }
// }


// Path: src/main/java/net/vz/mongodb/jackson/internal/MongoJacksonDeserializers.java
import net.vz.mongodb.jackson.DBRef;
import org.codehaus.jackson.map.BeanDescription;
import org.codehaus.jackson.map.BeanProperty;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.DeserializerProvider;
import org.codehaus.jackson.map.JsonDeserializer;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.module.SimpleDeserializers;
import org.codehaus.jackson.type.JavaType;
import java.util.Calendar;
import java.util.Date;

/*
 * Copyright 2011 VZ Netzwerke Ltd
 *
 * 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 net.vz.mongodb.jackson.internal;



/**
 * Deserializers for Mongo Jackson Mapper
 *
 * @author James Roper
 * @since 1.2
 */
public class MongoJacksonDeserializers extends SimpleDeserializers {
    public MongoJacksonDeserializers() {
        addDeserializer(Date.class, new DateDeserializer());
        addDeserializer(Calendar.class, new CalendarDeserializer());
    }

    public JsonDeserializer<?> findBeanDeserializer(JavaType type, DeserializationConfig config, DeserializerProvider provider, BeanDescription beanDesc, BeanProperty property) throws JsonMappingException {
        if (type.getRawClass() == DBRef.class) {
            if (!type.hasGenericTypes()) {
                throw new JsonMappingException("Property " + property + " doesn't declare object and key type");
            }
            JavaType objectType = type.containedType(0);
            JavaType keyType = type.containedType(1);
            return new DBRefDeserializer(objectType, keyType);
        }
        return super.findBeanDeserializer(type, config, provider, beanDesc, property);