blob: ffba4e443c2c7efb820489f99aabc3435db7f40f [file] [log] [blame]
Tatu Salorantadf6302f2011-12-23 20:05:35 -08001package com.fasterxml.jackson.databind.deser;
Tatu Salorantae4f23bb2011-12-23 00:31:35 -08002
Tatu Saloranta28bde072012-01-22 22:57:52 -08003import com.fasterxml.jackson.databind.*;
Tatu Salorantadf6302f2011-12-23 20:05:35 -08004import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
Tatu Salorantae4f23bb2011-12-23 00:31:35 -08005import com.fasterxml.jackson.databind.type.*;
6
Tatu Salorantae4f23bb2011-12-23 00:31:35 -08007/**
Tatue1429542012-01-24 17:01:45 -08008 * Abstract class that defines API used by {@link DeserializationContext}
9 * to construct actual
10 * {@link JsonDeserializer} instances (which are then cached by
11 * context and/or dedicated cache).
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080012 *<p>
13 * Since there are multiple broad categories of deserializers, there are
14 * multiple factory methods:
15 *<ul>
16 * <li>For JSON "Array" type, we need 2 methods: one to deal with expected
17 * Java arrays ({@link #createArrayDeserializer})
18 * and the other for other Java containers like {@link java.util.List}s
Tatue1429542012-01-24 17:01:45 -080019 * and {@link java.util.Set}s ({@link #createCollectionDeserializer}).
20 * Actually there is also a third method for "Collection-like" types;
21 * things like Scala collections that act like JDK collections but do not
22 * implement same interfaces.
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080023 * </li>
24 * <li>For JSON "Object" type, we need 2 methods: one to deal with
25 * expected Java {@link java.util.Map}s
26 * ({@link #createMapDeserializer}), and another for POJOs
Tatue1429542012-01-24 17:01:45 -080027 * ({@link #createBeanDeserializer}.
28 * As an additional twist there is also a callback for "Map-like" types,
29 * mostly to make it possible to support Scala Maps (which are NOT JDK
30 * Map compatible).
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080031 * </li>
Tatu Salorantaf0e232d2012-01-29 16:44:28 -080032 * <li>For Tree Model ({@link com.fasterxml.jackson.databind.JsonNode}) properties there is
Tatue1429542012-01-24 17:01:45 -080033 * {@link #createTreeDeserializer}
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080034 * <li>For enumerated types ({@link java.lang.Enum}) there is
Tatue1429542012-01-24 17:01:45 -080035 * {@link #createEnumDeserializer}
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080036 * </li>
Tatue1429542012-01-24 17:01:45 -080037 * <li>For all other types, {@link #createBeanDeserializer} is used.
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080038 * </ul>
39 *<p>
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080040 */
41public abstract class DeserializerFactory
42{
43 protected final static Deserializers[] NO_DESERIALIZERS = new Deserializers[0];
44
45 /*
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080046 /********************************************************
47 /* Configuration handling
48 /********************************************************
49 */
50
51 /**
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080052 * Convenience method for creating a new factory instance with additional deserializer
53 * provider.
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080054 */
Tatu69e3ed42012-01-26 13:42:24 -080055 public abstract DeserializerFactory withAdditionalDeserializers(Deserializers additional);
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080056
57 /**
58 * Convenience method for creating a new factory instance with additional
59 * {@link KeyDeserializers}.
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080060 */
Tatu69e3ed42012-01-26 13:42:24 -080061 public abstract DeserializerFactory withAdditionalKeyDeserializers(KeyDeserializers additional);
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080062
63 /**
64 * Convenience method for creating a new factory instance with additional
65 * {@link BeanDeserializerModifier}.
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080066 */
Tatu69e3ed42012-01-26 13:42:24 -080067 public abstract DeserializerFactory withDeserializerModifier(BeanDeserializerModifier modifier);
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080068
69 /**
70 * Convenience method for creating a new factory instance with additional
71 * {@link AbstractTypeResolver}.
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080072 */
Tatu69e3ed42012-01-26 13:42:24 -080073 public abstract DeserializerFactory withAbstractTypeResolver(AbstractTypeResolver resolver);
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080074
75 /**
76 * Convenience method for creating a new factory instance with additional
77 * {@link ValueInstantiators}.
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080078 */
Tatu69e3ed42012-01-26 13:42:24 -080079 public abstract DeserializerFactory withValueInstantiators(ValueInstantiators instantiators);
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080080
81 /*
82 /**********************************************************
83 /* Basic DeserializerFactory API:
84 /**********************************************************
85 */
86
87 /**
88 * Method that can be called to try to resolve an abstract type
89 * (interface, abstract class) into a concrete type, or at least
90 * something "more concrete" (abstract class instead of interface).
91 * Will either return passed type, or a more specific type.
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080092 */
93 public abstract JavaType mapAbstractType(DeserializationConfig config, JavaType type)
94 throws JsonMappingException;
95
96 /**
97 * Method that is to find all creators (constructors, factory methods)
98 * for the bean type to deserialize.
Tatu Salorantae4f23bb2011-12-23 00:31:35 -080099 */
Tatub37ff332012-01-24 16:19:36 -0800100 public abstract ValueInstantiator findValueInstantiator(DeserializationContext ctxt,
Tatu Saloranta28bde072012-01-22 22:57:52 -0800101 BeanDescription beanDesc)
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800102 throws JsonMappingException;
103
104 /**
105 * Method called to create (or, for completely immutable deserializers,
106 * reuse) a deserializer that can convert JSON content into values of
107 * specified Java "bean" (POJO) type.
108 * At this point it is known that the type is not otherwise recognized
109 * as one of structured types (array, Collection, Map) or a well-known
110 * JDK type (enum, primitives/wrappers, String); this method only
111 * gets called if other options are exhausted. This also means that
112 * this method can be overridden to add support for custom types.
113 *
114 * @param type Type to be deserialized
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800115 */
Tatub37ff332012-01-24 16:19:36 -0800116 public abstract JsonDeserializer<Object> createBeanDeserializer(DeserializationContext ctxt,
Tatu Salorantad6e90d02012-01-30 19:15:51 -0800117 JavaType type, BeanDescription beanDesc)
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800118 throws JsonMappingException;
119
120 /**
Tatu Saloranta2fd4ffd2012-02-17 22:40:13 -0800121 * Method called to create a deserializer that will use specified Builder
122 * class for building value instances.
Tatu Saloranta2fd4ffd2012-02-17 22:40:13 -0800123 */
124 public abstract JsonDeserializer<Object> createBuilderBasedDeserializer(
125 DeserializationContext ctxt, JavaType type, BeanDescription beanDesc,
126 Class<?> builderClass)
127 throws JsonMappingException;
Cowtowncodera73550e2015-10-21 14:18:58 -0700128
129
130 public abstract JsonDeserializer<?> createEnumDeserializer(DeserializationContext ctxt,
131 JavaType type, BeanDescription beanDesc)
132 throws JsonMappingException;
133
134 /**
135 * @since 2.7
136 */
137 public abstract JsonDeserializer<?> createReferenceDeserializer(DeserializationContext ctxt,
138 ReferenceType type, BeanDescription beanDesc)
139 throws JsonMappingException;
140
141 /**
142 * Method called to create and return a deserializer that can construct
143 * JsonNode(s) from JSON content.
144 */
145 public abstract JsonDeserializer<?> createTreeDeserializer(DeserializationConfig config,
146 JavaType type, BeanDescription beanDesc)
147 throws JsonMappingException;
Tatu Saloranta2fd4ffd2012-02-17 22:40:13 -0800148
149 /**
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800150 * Method called to create (or, for completely immutable deserializers,
151 * reuse) a deserializer that can convert JSON content into values of
152 * specified Java type.
153 *
154 * @param type Type to be deserialized
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800155 */
Tatub37ff332012-01-24 16:19:36 -0800156 public abstract JsonDeserializer<?> createArrayDeserializer(DeserializationContext ctxt,
Tatud0bb3152012-01-31 13:04:06 -0800157 ArrayType type, BeanDescription beanDesc)
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800158 throws JsonMappingException;
159
Tatub37ff332012-01-24 16:19:36 -0800160 public abstract JsonDeserializer<?> createCollectionDeserializer(DeserializationContext ctxt,
Tatud0bb3152012-01-31 13:04:06 -0800161 CollectionType type, BeanDescription beanDesc)
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800162 throws JsonMappingException;
163
Tatub37ff332012-01-24 16:19:36 -0800164 public abstract JsonDeserializer<?> createCollectionLikeDeserializer(DeserializationContext ctxt,
Tatu Saloranta49b71212012-01-30 22:13:21 -0800165 CollectionLikeType type, BeanDescription beanDesc)
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800166 throws JsonMappingException;
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800167
Tatub37ff332012-01-24 16:19:36 -0800168 public abstract JsonDeserializer<?> createMapDeserializer(DeserializationContext ctxt,
Tatud0bb3152012-01-31 13:04:06 -0800169 MapType type, BeanDescription beanDesc)
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800170 throws JsonMappingException;
171
Tatub37ff332012-01-24 16:19:36 -0800172 public abstract JsonDeserializer<?> createMapLikeDeserializer(DeserializationContext ctxt,
Tatu Saloranta49b71212012-01-30 22:13:21 -0800173 MapLikeType type, BeanDescription beanDesc)
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800174 throws JsonMappingException;
175
176 /**
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800177 * Method called to find if factory knows how to create a key deserializer
178 * for specified type; currently this means checking if a module has registered
179 * possible deserializers.
180 *
181 * @return Key deserializer to use for specified type, if one found; null if not
182 * (and default key deserializer should be used)
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800183 */
Tatub37ff332012-01-24 16:19:36 -0800184 public abstract KeyDeserializer createKeyDeserializer(DeserializationContext ctxt,
Tatud0bb3152012-01-31 13:04:06 -0800185 JavaType type)
Tatubf355ca2012-01-24 14:46:25 -0800186 throws JsonMappingException;
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800187
188 /**
189 * Method called to find and create a type information deserializer for given base type,
190 * if one is needed. If not needed (no polymorphic handling configured for type),
191 * should return null.
192 *<p>
193 * Note that this method is usually only directly called for values of container (Collection,
194 * array, Map) types and root values, but not for bean property values.
195 *
196 * @param baseType Declared base type of the value to deserializer (actual
197 * deserializer type will be this type or its subtype)
198 *
199 * @return Type deserializer to use for given base type, if one is needed; null if not.
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800200 */
Tatubf355ca2012-01-24 14:46:25 -0800201 public abstract TypeDeserializer findTypeDeserializer(DeserializationConfig config,
Tatu Saloranta49b71212012-01-30 22:13:21 -0800202 JavaType baseType)
Tatubf355ca2012-01-24 14:46:25 -0800203 throws JsonMappingException;
Tatu Salorantae4f23bb2011-12-23 00:31:35 -0800204}