-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathDeserializerFactory.java
More file actions
229 lines (203 loc) · 9.6 KB
/
DeserializerFactory.java
File metadata and controls
229 lines (203 loc) · 9.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package com.fasterxml.jackson.databind.deser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.type.*;
/**
* Abstract class that defines API used by {@link DeserializationContext}
* to construct actual
* {@link JsonDeserializer} instances (which are then cached by
* context and/or dedicated cache).
*<p>
* Since there are multiple broad categories of deserializers, there are
* multiple factory methods:
*<ul>
* <li>For JSON "Array" type, we need 2 methods: one to deal with expected
* Java arrays ({@link #createArrayDeserializer})
* and the other for other Java containers like {@link java.util.List}s
* and {@link java.util.Set}s ({@link #createCollectionDeserializer}).
* Actually there is also a third method for "Collection-like" types;
* things like Scala collections that act like JDK collections but do not
* implement same interfaces.
* </li>
* <li>For JSON "Object" type, we need 2 methods: one to deal with
* expected Java {@link java.util.Map}s
* ({@link #createMapDeserializer}), and another for POJOs
* ({@link #createBeanDeserializer}.
* As an additional twist there is also a callback for "Map-like" types,
* mostly to make it possible to support Scala Maps (which are NOT JDK
* Map compatible).
* </li>
* <li>For Tree Model ({@link com.fasterxml.jackson.databind.JsonNode}) properties there is
* {@link #createTreeDeserializer}
* <li>For enumerated types ({@link java.lang.Enum}) there is
* {@link #createEnumDeserializer}
* </li>
* <li>For all other types, {@link #createBeanDeserializer} is used.
* </ul>
*<p>
*/
public abstract class DeserializerFactory
{
protected final static Deserializers[] NO_DESERIALIZERS = new Deserializers[0];
/*
/********************************************************
/* Configuration handling
/********************************************************
*/
/**
* Convenience method for creating a new factory instance with additional deserializer
* provider.
*/
public abstract DeserializerFactory withAdditionalDeserializers(Deserializers additional);
/**
* Convenience method for creating a new factory instance with additional
* {@link KeyDeserializers}.
*/
public abstract DeserializerFactory withAdditionalKeyDeserializers(KeyDeserializers additional);
/**
* Convenience method for creating a new factory instance with additional
* {@link BeanDeserializerModifier}.
*/
public abstract DeserializerFactory withDeserializerModifier(BeanDeserializerModifier modifier);
/**
* Convenience method for creating a new factory instance with additional
* {@link AbstractTypeResolver}.
*/
public abstract DeserializerFactory withAbstractTypeResolver(AbstractTypeResolver resolver);
/**
* Convenience method for creating a new factory instance with additional
* {@link ValueInstantiators}.
*/
public abstract DeserializerFactory withValueInstantiators(ValueInstantiators instantiators);
/*
/**********************************************************
/* Basic DeserializerFactory API:
/**********************************************************
*/
/**
* Method that can be called to try to resolve an abstract type
* (interface, abstract class) into a concrete type, or at least
* something "more concrete" (abstract class instead of interface).
* Will either return passed type, or a more specific type.
*/
public abstract JavaType mapAbstractType(DeserializationConfig config, JavaType type)
throws JsonMappingException;
/**
* Method that is to find all creators (constructors, factory methods)
* for the bean type to deserialize.
*/
public abstract ValueInstantiator findValueInstantiator(DeserializationContext ctxt,
BeanDescription beanDesc)
throws JsonMappingException;
/**
* Method called to create (or, for completely immutable deserializers,
* reuse) a deserializer that can convert JSON content into values of
* specified Java "bean" (POJO) type.
* At this point it is known that the type is not otherwise recognized
* as one of structured types (array, Collection, Map) or a well-known
* JDK type (enum, primitives/wrappers, String); this method only
* gets called if other options are exhausted. This also means that
* this method can be overridden to add support for custom types.
*
* @param type Type to be deserialized
*/
public abstract JsonDeserializer<Object> createBeanDeserializer(DeserializationContext ctxt,
JavaType type, BeanDescription beanDesc)
throws JsonMappingException;
/**
* Method called to create a deserializer that will use specified Builder
* class for building value instances.
*/
public abstract JsonDeserializer<Object> createBuilderBasedDeserializer(
DeserializationContext ctxt, JavaType type, BeanDescription beanDesc,
Class<?> builderClass)
throws JsonMappingException;
public abstract JsonDeserializer<?> createEnumDeserializer(DeserializationContext ctxt,
JavaType type, BeanDescription beanDesc)
throws JsonMappingException;
/**
* @since 2.7
*/
public abstract JsonDeserializer<?> createReferenceDeserializer(DeserializationContext ctxt,
ReferenceType type, BeanDescription beanDesc)
throws JsonMappingException;
/**
* Method called to create and return a deserializer that can construct
* JsonNode(s) from JSON content.
*/
public abstract JsonDeserializer<?> createTreeDeserializer(DeserializationConfig config,
JavaType type, BeanDescription beanDesc)
throws JsonMappingException;
/**
* Method called to create (or, for completely immutable deserializers,
* reuse) a deserializer that can convert JSON content into values of
* specified Java type.
*
* @param type Type to be deserialized
*/
public abstract JsonDeserializer<?> createArrayDeserializer(DeserializationContext ctxt,
ArrayType type, BeanDescription beanDesc)
throws JsonMappingException;
public abstract JsonDeserializer<?> createCollectionDeserializer(DeserializationContext ctxt,
CollectionType type, BeanDescription beanDesc)
throws JsonMappingException;
public abstract JsonDeserializer<?> createCollectionLikeDeserializer(DeserializationContext ctxt,
CollectionLikeType type, BeanDescription beanDesc)
throws JsonMappingException;
public abstract JsonDeserializer<?> createTupleDeserializer(DeserializationContext ctxt,
TupleType type, BeanDescription beanDesc)
throws JsonMappingException;
public abstract JsonDeserializer<?> createMapDeserializer(DeserializationContext ctxt,
MapType type, BeanDescription beanDesc)
throws JsonMappingException;
public abstract JsonDeserializer<?> createMapLikeDeserializer(DeserializationContext ctxt,
MapLikeType type, BeanDescription beanDesc)
throws JsonMappingException;
/**
* Method called to find if factory knows how to create a key deserializer
* for specified type; currently this means checking if a module has registered
* possible deserializers.
*
* @return Key deserializer to use for specified type, if one found; null if not
* (and default key deserializer should be used)
*/
public abstract KeyDeserializer createKeyDeserializer(DeserializationContext ctxt,
JavaType type)
throws JsonMappingException;
/**
* Method called to find and create a type information deserializer for given base type,
* if one is needed. If not needed (no polymorphic handling configured for type),
* should return null.
*<p>
* Note that this method is usually only directly called for values of container (Collection,
* array, Map) types and root values, but not for bean property values.
*
* @param baseType Declared base type of the value to deserializer (actual
* deserializer type will be this type or its subtype)
*
* @return Type deserializer to use for given base type, if one is needed; null if not.
*/
public abstract TypeDeserializer findTypeDeserializer(DeserializationConfig config,
JavaType baseType)
throws JsonMappingException;
/**
* Method that can be used to check if databind module has explicitly declared deserializer
* for given (likely JDK) type, explicit meaning that there is specific deserializer for
* given type as opposed to auto-generated "Bean" deserializer. Factory itself will check
* for known JDK-provided types, but registered {@link com.fasterxml.jackson.databind.Module}s
* are also called to see if they might provide explicit deserializer.
*<p>
* Main use for this method is with Safe Default Typing (and generally Safe Polymorphic
* Deserialization), during which it is good to be able to check that given raw type
* is explicitly supported and as such "known type" (as opposed to potentially
* dangerous "gadget type" which could be exploited).
*<p>
* This matches {@code Deserializers.Base.hasDeserializerFor(Class)} method, which is
* the mechanism used to determine if a {@code Module} might provide an explicit
* deserializer instead of core databind.
*
* @since 2.11
*/
public abstract boolean hasExplicitDeserializerFor(DeserializationConfig config,
Class<?> valueType);
}