Skip to content

Commit c52b0d1

Browse files
committed
Fix #1888
1 parent 7e51ede commit c52b0d1

19 files changed

+106
-104
lines changed

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ Versions: 3.x (for earlier see VERSION-2.x)
1818
(reported by timo-schmid@github)
1919
#1789: Add `createGenerator` methods in `ObjectMapper`, `ObjectWriter`
2020
#1790: Add `createParser` methods in `ObjectMapper`, `ObjectReader`
21+
#1888: Merge `ResolvableSerializer` into `JsonSerializer`, `ResolvableDeserializer`
22+
into `JsonDeserializer`
2123
- Remove `MappingJsonFactory`

src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,11 @@ public final JsonDeserializer<Object> findContextualValueDeserializer(JavaType t
576576
* performing any contextualization (unlike {@link #findContextualValueDeserializer})
577577
* or checking for need to create a {@link TypeDeserializer} (unlike
578578
* {@link #findRootValueDeserializer(JavaType)}.
579-
* This method is usually called from within {@link ResolvableDeserializer#resolve},
579+
* This method is usually called from within {@link JsonDeserializer#resolve},
580580
* and expectation is that caller then calls either
581581
* {@link #handlePrimaryContextualization(JsonDeserializer, BeanProperty, JavaType)} or
582582
* {@link #handleSecondaryContextualization(JsonDeserializer, BeanProperty, JavaType)} at a
583583
* later point, as necessary.
584-
*
585-
* @since 2.5
586584
*/
587585
public final JsonDeserializer<Object> findNonContextualValueDeserializer(JavaType type)
588586
throws JsonMappingException

src/main/java/com/fasterxml/jackson/databind/JsonDeserializer.java

+28-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*<p>
2323
* If deserializer is an aggregate one -- meaning it delegates handling of some
2424
* of its contents by using other deserializer(s) -- it typically also needs
25-
* to implement {@link com.fasterxml.jackson.databind.deser.ResolvableDeserializer},
25+
* to implement {@link #resolve}
2626
* which can locate dependant deserializers. This is important to allow dynamic
2727
* overrides of deserializers; separate call interface is needed to separate
2828
* resolution of dependant deserializers (which may have cyclic link back
@@ -36,16 +36,32 @@
3636
* {@link com.fasterxml.jackson.databind.deser.ContextualDeserializer#createContextual}
3737
* is passed information on property, and can create a newly configured
3838
* deserializer for handling that particular property.
39-
*<p>
40-
* If both
41-
* {@link com.fasterxml.jackson.databind.deser.ResolvableDeserializer} and
42-
* {@link com.fasterxml.jackson.databind.deser.ContextualDeserializer}
43-
* are implemented, resolution of deserializers occurs before
44-
* contextualization.
39+
*<br />
40+
* Resolution of deserializers occurs before contextualization.
4541
*/
4642
public abstract class JsonDeserializer<T>
4743
implements NullValueProvider
4844
{
45+
/*
46+
/**********************************************************
47+
/* Initialization, with former `ResolvableDeserializer`
48+
/**********************************************************
49+
*/
50+
51+
/**
52+
* Method called after deserializer instance has been constructed
53+
* (and registered as necessary by provider objects),
54+
* but before it has returned it to the caller.
55+
* Called object can then resolve its dependencies to other types,
56+
* including self-references (direct or indirect).
57+
*
58+
* @param ctxt Context to use for accessing configuration, resolving
59+
* secondary deserializers
60+
*/
61+
public void resolve(DeserializationContext ctxt) throws JsonMappingException {
62+
// Default implementation does nothing
63+
}
64+
4965
/*
5066
/**********************************************************
5167
/* Main deserialization methods
@@ -209,14 +225,14 @@ public JsonDeserializer<?> replaceDelegatee(JsonDeserializer<?> delegatee) {
209225
* usable for other properties of same type (type for which instance
210226
* was created).
211227
*<p>
212-
* Note that cached instances are still resolved on per-property basis,
213-
* if instance implements {@link com.fasterxml.jackson.databind.deser.ResolvableDeserializer}:
214-
* cached instance is just as the base. This means that in most cases it is safe to
228+
* Note that cached instances are still contextualized on per-property basis
229+
* (but note that {@link JsonDeserializer#resolve(DeserializationContext)}d
230+
* just once!)
231+
* This means that in most cases it is safe to
215232
* cache instances; however, it only makes sense to cache instances
216233
* if instantiation is expensive, or if instances are heavy-weight.
217234
*<p>
218-
* Default implementation returns false, to indicate that no caching
219-
* is done.
235+
* Default implementation returns false, to indicate that no caching is done.
220236
*/
221237
public boolean isCachable() { return false; }
222238

src/main/java/com/fasterxml/jackson/databind/JsonSerializer.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public abstract class JsonSerializer<T>
5151
{
5252
/*
5353
/**********************************************************
54-
/* Initialization, with former `ResolvableSerializer
54+
/* Initialization, with former `ResolvableSerializer`
5555
/**********************************************************
5656
*/
5757

@@ -67,8 +67,7 @@ public abstract class JsonSerializer<T>
6767
* @param provider Provider that has constructed serializer this method
6868
* is called on.
6969
*/
70-
public void resolve(SerializerProvider provider)
71-
throws JsonMappingException {
70+
public void resolve(SerializerProvider provider) throws JsonMappingException {
7271
// Default implementation does nothing
7372
}
7473

src/main/java/com/fasterxml/jackson/databind/KeyDeserializer.java

+26
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,32 @@
99
*/
1010
public abstract class KeyDeserializer
1111
{
12+
/*
13+
/**********************************************************
14+
/* Initialization, with former `ResolvableDeserializer`
15+
/**********************************************************
16+
*/
17+
18+
/**
19+
* Method called after deserializer instance has been constructed
20+
* (and registered as necessary by provider objects),
21+
* but before it has returned it to the caller.
22+
* Called object can then resolve its dependencies to other types,
23+
* including self-references (direct or indirect).
24+
*
25+
* @param ctxt Context to use for accessing configuration, resolving
26+
* secondary deserializers
27+
*/
28+
public void resolve(DeserializationContext ctxt) throws JsonMappingException {
29+
// Default implementation does nothing
30+
}
31+
32+
/*
33+
/**********************************************************
34+
/* Main API
35+
/**********************************************************
36+
*/
37+
1238
/**
1339
* Method called to deserialize a {@link java.util.Map} key from JSON property name.
1440
*/

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
public abstract class BeanDeserializerBase
2727
extends StdDeserializer<Object>
28-
implements ContextualDeserializer, ResolvableDeserializer,
28+
implements ContextualDeserializer,
2929
ValueInstantiator.Gettable,
3030
java.io.Serializable
3131
{

src/main/java/com/fasterxml/jackson/databind/deser/ContextualDeserializer.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
* have differing behavior depending on what kind of property is being deserialized.
1212
*<p>
1313
* Note that in cases where deserializer needs both contextualization and
14-
* resolution -- that is, implements both this interface and {@link ResolvableDeserializer}
15-
* -- resolution via {@link ResolvableDeserializer} occurs first, and contextual
14+
* resolution -- resolution occurs first, and contextual
1615
* resolution (via this interface) later on.
1716
*/
1817
public interface ContextualDeserializer

src/main/java/com/fasterxml/jackson/databind/deser/DefaultDeserializationContext.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ public JsonDeserializer<Object> deserializerInstance(Annotated ann, Object deser
234234
}
235235
}
236236
// First: need to resolve
237-
if (deser instanceof ResolvableDeserializer) {
238-
((ResolvableDeserializer) deser).resolve(this);
239-
}
237+
deser.resolve(this);
240238
return (JsonDeserializer<Object>) deser;
241239
}
242240

@@ -275,9 +273,7 @@ public final KeyDeserializer keyDeserializerInstance(Annotated ann, Object deser
275273
}
276274
}
277275
// First: need to resolve
278-
if (deser instanceof ResolvableDeserializer) {
279-
((ResolvableDeserializer) deser).resolve(this);
280-
}
276+
deser.resolve(this);
281277
return deser;
282278
}
283279

src/main/java/com/fasterxml/jackson/databind/deser/DeserializerCache.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void flushCachedDeserializers() {
120120
* Key deserializers can be accessed using {@link #findKeyDeserializer}.
121121
*<p>
122122
* Note also that deserializer returned is guaranteed to be resolved
123-
* (if it is of type {@link ResolvableDeserializer}), but
123+
* (see {@link JsonDeserializer#resolve}), but
124124
* not contextualized (wrt {@link ContextualDeserializer}): caller
125125
* has to handle latter if necessary.
126126
*
@@ -168,9 +168,7 @@ public KeyDeserializer findKeyDeserializer(DeserializationContext ctxt,
168168
return _handleUnknownKeyDeserializer(ctxt, type);
169169
}
170170
// First: need to resolve?
171-
if (kd instanceof ResolvableDeserializer) {
172-
((ResolvableDeserializer) kd).resolve(ctxt);
173-
}
171+
kd.resolve(ctxt);
174172
return kd;
175173
}
176174

@@ -288,9 +286,10 @@ protected JsonDeserializer<Object> _createAndCache2(DeserializationContext ctxt,
288286
/* Need to resolve? Mostly done for bean deserializers; required for
289287
* resolving cyclic references.
290288
*/
291-
if (deser instanceof ResolvableDeserializer) {
292-
_incompleteDeserializers.put(type, deser);
293-
((ResolvableDeserializer)deser).resolve(ctxt);
289+
_incompleteDeserializers.put(type, deser);
290+
try {
291+
deser.resolve(ctxt);
292+
} finally {
294293
_incompleteDeserializers.remove(type);
295294
}
296295
if (addToCache) {

src/main/java/com/fasterxml/jackson/databind/deser/Deserializers.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public JsonDeserializer<?> findReferenceDeserializer(ReferenceType refType,
100100
* the type information deserializer to use; should usually be used as is when constructing
101101
* array deserializer.
102102
* @param elementDeserializer Deserializer to use for elements, if explicitly defined (by using
103-
* annotations, for exmple). May be null, in which case it should be resolved here (or using
104-
* {@link ResolvableDeserializer} callback)
103+
* annotations, for example). May be null, in which case it will need to be resolved
104+
* by deserializer at a later point.
105105
*
106106
* @return Deserializer to use for the type; or null if this provider does not know how to construct it
107107
*/
@@ -110,7 +110,6 @@ public JsonDeserializer<?> findArrayDeserializer(ArrayType type,
110110
TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
111111
throws JsonMappingException;
112112

113-
114113
/**
115114
* Method called to locate serializer for specified {@link java.util.Collection} (List, Set etc) type.
116115
*<p>
@@ -127,8 +126,8 @@ public JsonDeserializer<?> findArrayDeserializer(ArrayType type,
127126
* the type information deserializer to use; should usually be used as is when constructing
128127
* array deserializer.
129128
* @param elementDeserializer Deserializer to use for elements, if explicitly defined (by using
130-
* annotations, for exmple). May be null, in which case it should be resolved here (or using
131-
* {@link ResolvableDeserializer} callback)
129+
* annotations, for example). May be null, in which case it will need to be resolved
130+
* by deserializer at a later point.
132131
*
133132
* @return Deserializer to use for the type; or null if this provider does not know how to construct it
134133
*/
@@ -155,8 +154,8 @@ public JsonDeserializer<?> findCollectionDeserializer(CollectionType type,
155154
* the type information deserializer to use; should usually be used as is when constructing
156155
* array deserializer.
157156
* @param elementDeserializer Deserializer to use for elements, if explicitly defined (by using
158-
* annotations, for exmple). May be null, in which case it should be resolved here (or using
159-
* {@link ResolvableDeserializer} callback)
157+
* annotations, for example). May be null, in which case it will need to be resolved
158+
* by deserializer at a later point.
160159
*
161160
* @return Deserializer to use for the type; or null if this provider does not know how to construct it
162161
*/
@@ -176,7 +175,7 @@ public JsonDeserializer<?> findCollectionLikeDeserializer(CollectionLikeType typ
176175
* Similarly, a {@link KeyDeserializer} may be passed, but this is only done if there is
177176
* a specific configuration override (annotations) to indicate instance to use.
178177
* Otherwise null is passed, and key deserializer needs to be obtained later during
179-
* resolution (using {@link ResolvableDeserializer#resolve}).
178+
* resolution of map serializer constructed here.
180179
*
181180
* @param type Type of {@link java.util.Map} instances to deserialize
182181
* @param config Configuration in effect
@@ -188,8 +187,8 @@ public JsonDeserializer<?> findCollectionLikeDeserializer(CollectionLikeType typ
188187
* the type information deserializer to use; should usually be used as is when constructing
189188
* array deserializer.
190189
* @param elementDeserializer Deserializer to use for elements, if explicitly defined (by using
191-
* annotations, for exmple). May be null, in which case it should be resolved here (or using
192-
* {@link ResolvableDeserializer} callback)
190+
* annotations, for example). May be null, in which case it will need to be resolved
191+
* by deserializer at a later point.
193192
*
194193
* @return Deserializer to use for the type; or null if this provider does not know how to construct it
195194
*/
@@ -212,7 +211,7 @@ public JsonDeserializer<?> findMapDeserializer(MapType type,
212211
* Similarly, a {@link KeyDeserializer} may be passed, but this is only done if there is
213212
* a specific configuration override (annotations) to indicate instance to use.
214213
* Otherwise null is passed, and key deserializer needs to be obtained later during
215-
* resolution (using {@link ResolvableDeserializer#resolve}).
214+
* resolution, by deserializer constructed here.
216215
*
217216
* @param type Type of {@link java.util.Map} instances to deserialize
218217
* @param config Configuration in effect
@@ -224,8 +223,8 @@ public JsonDeserializer<?> findMapDeserializer(MapType type,
224223
* the type information deserializer to use; should usually be used as is when constructing
225224
* array deserializer.
226225
* @param elementDeserializer Deserializer to use for elements, if explicitly defined (by using
227-
* annotations, for exmple). May be null, in which case it should be resolved here (or using
228-
* {@link ResolvableDeserializer} callback)
226+
* annotations, for example). May be null, in which case it will need to be resolved
227+
* by deserializer at a later point.
229228
*
230229
* @return Deserializer to use for the type; or null if this provider does not know how to construct it
231230
*/

src/main/java/com/fasterxml/jackson/databind/deser/ResolvableDeserializer.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.fasterxml.jackson.databind.DeserializationContext;
44
import com.fasterxml.jackson.databind.JsonMappingException;
55

6-
/**
6+
/*
77
* Interface used to indicate deserializers that want to do post-processing
88
* after construction but before being returned to caller (and possibly cached)
99
* and used.
@@ -27,19 +27,17 @@
2727
* resolution -- that is, implements both this interface and {@link ContextualDeserializer}
2828
* -- resolution via this interface occurs first, and contextual
2929
* resolution (using {@link ContextualDeserializer}) later on.
30+
*
31+
* @deprecated Since 3.0: method demoted to <code>JsonSerializer</code>
3032
*/
33+
/**
34+
* Leftover interface from 2.x: method now merged in <code>JsonSerializer</code>
35+
*
36+
* @deprecated Since 3.0: method demoted to <code>JsonSerializer</code>
37+
*/
38+
@Deprecated
3139
public interface ResolvableDeserializer
3240
{
33-
/**
34-
* Method called after deserializer instance has been constructed
35-
* (and registered as necessary by provider objects),
36-
* but before it has returned it to the caller.
37-
* Called object can then resolve its dependencies to other types,
38-
* including self-references (direct or indirect).
39-
*
40-
* @param ctxt Context to use for accessing configuration, resolving
41-
* secondary deserializers
42-
*/
4341
public abstract void resolve(DeserializationContext ctxt)
4442
throws JsonMappingException;
4543
}

src/main/java/com/fasterxml/jackson/databind/deser/std/DelegatingDeserializer.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
* that mostly delegate functionality to another deserializer implementation
1616
* (possibly forming a chaing of deserializers delegating functionality
1717
* in some cases)
18-
*
19-
* @since 2.1
2018
*/
2119
public abstract class DelegatingDeserializer
2220
extends StdDeserializer<Object>
23-
implements ContextualDeserializer, ResolvableDeserializer
21+
implements ContextualDeserializer
2422
{
2523
private static final long serialVersionUID = 1L;
2624

@@ -54,8 +52,8 @@ public DelegatingDeserializer(JsonDeserializer<?> d)
5452

5553
@Override
5654
public void resolve(DeserializationContext ctxt) throws JsonMappingException {
57-
if (_delegatee instanceof ResolvableDeserializer) {
58-
((ResolvableDeserializer) _delegatee).resolve(ctxt);
55+
if (_delegatee != null) {
56+
_delegatee.resolve(ctxt);
5957
}
6058
}
6159

src/main/java/com/fasterxml/jackson/databind/deser/std/EnumMapDeserializer.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55

66
import com.fasterxml.jackson.core.*;
77
import com.fasterxml.jackson.databind.*;
8-
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
9-
import com.fasterxml.jackson.databind.deser.NullValueProvider;
10-
import com.fasterxml.jackson.databind.deser.ResolvableDeserializer;
11-
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
12-
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
8+
import com.fasterxml.jackson.databind.deser.*;
139
import com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator;
1410
import com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer;
1511
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
@@ -24,7 +20,7 @@
2420
@SuppressWarnings({ "unchecked", "rawtypes" })
2521
public class EnumMapDeserializer
2622
extends ContainerDeserializerBase<EnumMap<?,?>>
27-
implements ContextualDeserializer, ResolvableDeserializer
23+
implements ContextualDeserializer
2824
{
2925
private static final long serialVersionUID = 1;
3026

src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
@JacksonStdImpl
3030
public class MapDeserializer
3131
extends ContainerDeserializerBase<Map<Object,Object>>
32-
implements ContextualDeserializer, ResolvableDeserializer
32+
implements ContextualDeserializer
3333
{
3434
private static final long serialVersionUID = 1L;
3535

0 commit comments

Comments
 (0)