Skip to content

Commit 3edb591

Browse files
committed
Merge branch '2.7' into 2.8
2 parents e2184aa + 4e94c0e commit 3edb591

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project: jackson-databind
1313
(reported by TomMarkuske@github)
1414
#1389 Problem with handling of multi-argument creator with Enums
1515
(fix contributed by Pavel P)
16+
#1392: Custom UnmodifiableSetMixin Fails in Jackson 2.7+ but works in Jackson 2.6
17+
(reported by Rob W)
1618
#1395: Problems deserializing primitive `long` field while using `TypeResolverBuilder`
1719
(reported by UghZan3@github)
1820

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ protected BeanDeserializerBase(BeanDeserializerBuilder builder,
229229
_objectIdReader = builder.getObjectIdReader();
230230
_nonStandardCreation = (_unwrappedPropertyHandler != null)
231231
|| _valueInstantiator.canCreateUsingDelegate()
232+
|| _valueInstantiator.canCreateUsingArrayDelegate() // new in 2.7
232233
|| _valueInstantiator.canCreateFromObjectWith()
233234
|| !_valueInstantiator.canCreateUsingDefault()
234235
;

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public boolean canInstantiate() {
7373
|| canCreateFromInt() || canCreateFromLong()
7474
|| canCreateFromDouble() || canCreateFromBoolean();
7575
}
76-
76+
7777
/**
7878
* Method that can be called to check whether a String-based creator
7979
* is available for this instantiator
@@ -103,7 +103,7 @@ public boolean canInstantiate() {
103103
* creator is available to use (to call {@link #createFromDouble}).
104104
*/
105105
public boolean canCreateFromBoolean() { return false; }
106-
106+
107107
/**
108108
* Method that can be called to check whether a default creator (constructor,
109109
* or no-arg static factory method)
@@ -122,6 +122,8 @@ public boolean canInstantiate() {
122122
* Method that can be called to check whether a array-delegate-based creator
123123
* (single-arg constructor or factory method)
124124
* is available for this instantiator
125+
*
126+
* @since 2.7
125127
*/
126128
public boolean canCreateUsingArrayDelegate() { return false; }
127129

@@ -161,9 +163,11 @@ public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig confi
161163
* non-null type is returned, deserializer will bind JSON into specified
162164
* type (using standard deserializer for that type), and pass that to
163165
* instantiator.
166+
*
167+
* @since 2.7
164168
*/
165169
public JavaType getArrayDelegateType(DeserializationConfig config) { return null; }
166-
170+
167171
/*
168172
/**********************************************************
169173
/* Instantiation methods for JSON Object

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,24 @@ public CollectionDeserializer createContextual(DeserializationContext ctxt,
172172
{
173173
// May need to resolve types for delegate-based creators:
174174
JsonDeserializer<Object> delegateDeser = null;
175-
if ((_valueInstantiator != null) && _valueInstantiator.canCreateUsingDelegate()) {
176-
JavaType delegateType = _valueInstantiator.getDelegateType(ctxt.getConfig());
177-
if (delegateType == null) {
178-
throw new IllegalArgumentException("Invalid delegate-creator definition for "+_collectionType
179-
+": value instantiator ("+_valueInstantiator.getClass().getName()
180-
+") returned true for 'canCreateUsingDelegate()', but null for 'getDelegateType()'");
175+
if (_valueInstantiator != null) {
176+
if (_valueInstantiator.canCreateUsingDelegate()) {
177+
JavaType delegateType = _valueInstantiator.getDelegateType(ctxt.getConfig());
178+
if (delegateType == null) {
179+
throw new IllegalArgumentException("Invalid delegate-creator definition for "+_collectionType
180+
+": value instantiator ("+_valueInstantiator.getClass().getName()
181+
+") returned true for 'canCreateUsingDelegate()', but null for 'getDelegateType()'");
182+
}
183+
delegateDeser = findDeserializer(ctxt, delegateType, property);
184+
} else if (_valueInstantiator.canCreateUsingArrayDelegate()) {
185+
JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
186+
if (delegateType == null) {
187+
throw new IllegalArgumentException("Invalid array-delegate-creator definition for "+_collectionType
188+
+": value instantiator ("+_valueInstantiator.getClass().getName()
189+
+") returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'");
190+
}
191+
delegateDeser = findDeserializer(ctxt, delegateType, property);
181192
}
182-
delegateDeser = findDeserializer(ctxt, delegateType, property);
183193
}
184194
// [databind#1043]: allow per-property allow-wrapping of single overrides:
185195
// 11-Dec-2015, tatu: Should we pass basic `Collection.class`, or more refined? Mostly
@@ -204,7 +214,7 @@ public CollectionDeserializer createContextual(DeserializationContext ctxt,
204214
}
205215
return withResolved(delegateDeser, valueDeser, valueTypeDeser, unwrapSingle);
206216
}
207-
217+
208218
/*
209219
/**********************************************************
210220
/* ContainerDeserializerBase API
@@ -236,9 +246,9 @@ public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt)
236246
return (Collection<Object>) _valueInstantiator.createUsingDelegate(ctxt,
237247
_delegateDeserializer.deserialize(p, ctxt));
238248
}
239-
/* [JACKSON-620]: empty String may be ok; bit tricky to check, however, since
240-
* there is also possibility of "auto-wrapping" of single-element arrays.
241-
* Hence we only accept empty String here.
249+
/* Empty String may be ok; bit tricky to check, however, since
250+
* there is also possibility of "auto-wrapping" of single-element arrays.
251+
* Hence we only accept empty String here.
242252
*/
243253
if (p.hasToken(JsonToken.VALUE_STRING)) {
244254
String str = p.getText();

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,19 +281,27 @@ public Object createFromObjectWith(DeserializationContext ctxt, Object[] args) t
281281
@Override
282282
public Object createUsingDelegate(DeserializationContext ctxt, Object delegate) throws IOException
283283
{
284+
// 04-Oct-2016, tatu: Need delegation to work around [databind#1392]...
285+
if (_delegateCreator == null) {
286+
if (_arrayDelegateCreator != null) {
287+
return _createUsingDelegate(_arrayDelegateCreator, _arrayDelegateArguments, ctxt, delegate);
288+
}
289+
}
284290
return _createUsingDelegate(_delegateCreator, _delegateArguments, ctxt, delegate);
285291
}
286292

287293
@Override
288294
public Object createUsingArrayDelegate(DeserializationContext ctxt, Object delegate) throws IOException
289295
{
290-
if (_arrayDelegateCreator == null) { // sanity-check; caller should check
291-
// fallback to the classic delegate creator
292-
return createUsingDelegate(ctxt, delegate);
296+
if (_arrayDelegateCreator == null) {
297+
if (_delegateCreator != null) { // sanity-check; caller should check
298+
// fallback to the classic delegate creator
299+
return createUsingDelegate(ctxt, delegate);
300+
}
293301
}
294302
return _createUsingDelegate(_arrayDelegateCreator, _arrayDelegateArguments, ctxt, delegate);
295303
}
296-
304+
297305
/*
298306
/**********************************************************
299307
/* Public API implementation; instantiation from JSON scalars

src/test/java/com/fasterxml/jackson/failing/UnmodifiableSetTyping1392Test.java renamed to src/test/java/com/fasterxml/jackson/databind/creators/ArrayDelegatorCreatorForCollectionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.databind.creators;
22

33
import java.util.Collections;
44
import java.util.Set;
@@ -7,7 +7,7 @@
77

88
import com.fasterxml.jackson.databind.*;
99

10-
public class UnmodifiableSetTyping1392Test extends BaseMapTest
10+
public class ArrayDelegatorCreatorForCollectionTest extends BaseMapTest
1111
{
1212
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY)
1313
abstract static class UnmodifiableSetMixin {

0 commit comments

Comments
 (0)