Skip to content

Commit 48509f3

Browse files
committed
Minor post-merge cleanup (naming); catch an unhandled runtime exception wrt initialization
1 parent 6db505c commit 48509f3

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,7 @@ public TypeDeserializer findTypeDeserializer(DeserializationConfig config,
18011801
// map to better type here
18021802
try {
18031803
return b.buildTypeDeserializer(config, baseType, subtypes);
1804-
} catch (IllegalArgumentException e0) {
1804+
} catch (IllegalArgumentException | IllegalStateException e0) {
18051805
InvalidDefinitionException e = InvalidDefinitionException.from((JsonParser) null,
18061806
ClassUtil.exceptionMessage(e0), baseType);
18071807
e.initCause(e0);
@@ -2015,7 +2015,7 @@ public TypeDeserializer findPropertyTypeDeserializer(DeserializationConfig confi
20152015
config, annotated, baseType);
20162016
try {
20172017
return b.buildTypeDeserializer(config, baseType, subtypes);
2018-
} catch (IllegalArgumentException e0) {
2018+
} catch (IllegalArgumentException | IllegalStateException e0) {
20192019
InvalidDefinitionException e = InvalidDefinitionException.from((JsonParser) null,
20202020
ClassUtil.exceptionMessage(e0), baseType);
20212021
e.initCause(e0);

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsDeductionTypeDeserializer.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
import com.fasterxml.jackson.databind.util.TokenBuffer;
1616

1717
/**
18-
* A {@link TypeDeserializer} capable of deducing polymorphic types based on the fields available. Deduction
19-
* is limited to the <i>names</i> of child fields (not their values or, consequently, any nested descendants).
20-
* Exceptions will be thrown if not enough unique information is present to select a single subtype.
18+
* A {@link TypeDeserializer} capable of deducing polymorphic types based on the
19+
* fields available. Deduction is limited to the <i>names</i> of child properties
20+
* (not their values or, consequently, any nested descendants).
21+
* Exceptions will be thrown if not enough unique information is present
22+
* to select a single subtype.
2123
* <p>
22-
* The current deduction process <b>does not</b> support pojo-hierarchies such that the
23-
* absence of child fields infers a parent type. That is, every deducible subtype
24+
* The current deduction process <b>does not</b> support pojo-hierarchies such that
25+
* the absence of child fields infers a parent type. That is, every deducible subtype
2426
* MUST have some unique fields and the input data MUST contain said unique fields
2527
* to provide a <i>positive match</i>.
2628
*/
@@ -33,7 +35,9 @@ public class AsDeductionTypeDeserializer extends AsPropertyTypeDeserializer
3335
// Bitmap of available fields in each subtype (including its parents)
3436
private final Map<BitSet, String> subtypeFingerprints;
3537

36-
public AsDeductionTypeDeserializer(JavaType bt, TypeIdResolver idRes, JavaType defaultImpl, DeserializationConfig config, Collection<NamedType> subtypes) {
38+
public AsDeductionTypeDeserializer(JavaType bt, TypeIdResolver idRes, JavaType defaultImpl,
39+
DeserializationConfig config, Collection<NamedType> subtypes)
40+
{
3741
super(bt, idRes, null, false, defaultImpl, null);
3842
fieldBitIndex = new HashMap<>();
3943
subtypeFingerprints = buildFingerprints(config, subtypes);

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsPropertyTypeDeserializer.java

+18-12
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import java.io.IOException;
44

55
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
6+
67
import com.fasterxml.jackson.core.JsonParser;
78
import com.fasterxml.jackson.core.JsonToken;
89
import com.fasterxml.jackson.core.util.JsonParserSequence;
9-
import com.fasterxml.jackson.databind.BeanProperty;
10-
import com.fasterxml.jackson.databind.DeserializationContext;
11-
import com.fasterxml.jackson.databind.DeserializationFeature;
12-
import com.fasterxml.jackson.databind.JavaType;
13-
import com.fasterxml.jackson.databind.JsonDeserializer;
14-
import com.fasterxml.jackson.databind.MapperFeature;
10+
11+
import com.fasterxml.jackson.databind.*;
1512
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
1613
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
1714
import com.fasterxml.jackson.databind.util.TokenBuffer;
@@ -31,9 +28,10 @@ public class AsPropertyTypeDeserializer extends AsArrayTypeDeserializer
3128

3229
protected final As _inclusion;
3330

34-
protected final String msgMissingId = _property == null ?
35-
String.format("missing type id property '%s'", _typePropertyName) :
36-
String.format("missing type id property '%s' (for POJO property '%s')", _typePropertyName, _property.getName());
31+
// @since 2.12.2 (see [databind#3055]
32+
protected final String _msgForMissingId = (_property == null)
33+
? String.format("missing type id property '%s'", _typePropertyName)
34+
: String.format("missing type id property '%s' (for POJO property '%s')", _typePropertyName, _property.getName());
3735

3836
/**
3937
* @since 2.8
@@ -95,7 +93,7 @@ public Object deserializeTypedFromObject(JsonParser p, DeserializationContext ct
9593
* But this can also be due to some custom handling: so, if "defaultImpl"
9694
* is defined, it will be asked to handle this case.
9795
*/
98-
return _deserializeTypedUsingDefaultImpl(p, ctxt, null, msgMissingId);
96+
return _deserializeTypedUsingDefaultImpl(p, ctxt, null, _msgForMissingId);
9997
}
10098
// Ok, let's try to find the property. But first, need token buffer...
10199
TokenBuffer tb = null;
@@ -114,7 +112,7 @@ public Object deserializeTypedFromObject(JsonParser p, DeserializationContext ct
114112
tb.writeFieldName(name);
115113
tb.copyCurrentStructure(p);
116114
}
117-
return _deserializeTypedUsingDefaultImpl(p, ctxt, tb, msgMissingId);
115+
return _deserializeTypedUsingDefaultImpl(p, ctxt, tb, _msgForMissingId);
118116
}
119117

120118
protected Object _deserializeTypedForId(JsonParser p, DeserializationContext ctxt,
@@ -139,9 +137,17 @@ protected Object _deserializeTypedForId(JsonParser p, DeserializationContext ctx
139137
return deser.deserialize(p, ctxt);
140138
}
141139

140+
@Deprecated // since 2.12.2 (remove from 2.14 or later)
141+
protected Object _deserializeTypedUsingDefaultImpl(JsonParser p,
142+
DeserializationContext ctxt, TokenBuffer tb) throws IOException {
143+
return _deserializeTypedUsingDefaultImpl(p, ctxt, tb, null);
144+
}
145+
142146
// off-lined to keep main method lean and mean...
147+
// @since 2.12.2 (last arg added)
143148
protected Object _deserializeTypedUsingDefaultImpl(JsonParser p,
144-
DeserializationContext ctxt, TokenBuffer tb, String priorFailureMsg) throws IOException
149+
DeserializationContext ctxt, TokenBuffer tb, String priorFailureMsg)
150+
throws IOException
145151
{
146152
// May have default implementation to use
147153
// 13-Oct-2020, tatu: As per [databind#2775], need to be careful to

src/test/java/com/fasterxml/jackson/databind/jsontype/TestPolymorphicDeduction.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
import java.util.List;
44
import java.util.Map;
55

6-
import com.fasterxml.jackson.annotation.JsonProperty;
76
import com.fasterxml.jackson.annotation.JsonSubTypes;
87
import com.fasterxml.jackson.annotation.JsonTypeInfo;
8+
99
import com.fasterxml.jackson.databind.BaseMapTest;
1010
import com.fasterxml.jackson.databind.DeserializationFeature;
1111
import com.fasterxml.jackson.databind.JavaType;
1212
import com.fasterxml.jackson.databind.MapperFeature;
1313
import com.fasterxml.jackson.databind.ObjectMapper;
14+
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
1415
import com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
1516
import com.fasterxml.jackson.databind.json.JsonMapper;
1617
import com.fasterxml.jackson.databind.type.TypeFactory;
18+
1719
import static com.fasterxml.jackson.annotation.JsonSubTypes.Type;
1820
import static com.fasterxml.jackson.annotation.JsonTypeInfo.Id.DEDUCTION;
1921

@@ -152,7 +154,7 @@ public void testAmbiguousClasses() throws Exception {
152154
.build();
153155
/*Cat cat =*/ mapper.readValue(liveCatJson, Cat.class);
154156
fail("Should not get here");
155-
} catch (IllegalStateException e) {
157+
} catch (InvalidDefinitionException e) {
156158
verifyException(e, "Subtypes ");
157159
verifyException(e, "have the same signature");
158160
verifyException(e, "cannot be uniquely deduced");

0 commit comments

Comments
 (0)