@@ -29,14 +29,15 @@ class FactoryBasedEnumDeserializer
29
29
{
30
30
private static final long serialVersionUID = 1 ;
31
31
32
- // Marker type; null if String expected; otherwise numeric wrapper
32
+ // Marker type; null if String expected; otherwise usually numeric wrapper
33
33
protected final JavaType _inputType ;
34
- protected final boolean _hasArgs ;
35
34
protected final AnnotatedMethod _factory ;
36
35
protected final JsonDeserializer <?> _deser ;
37
36
protected final ValueInstantiator _valueInstantiator ;
38
37
protected final SettableBeanProperty [] _creatorProps ;
39
38
39
+ protected final boolean _hasArgs ;
40
+
40
41
/**
41
42
* Lazily instantiated property-based creator.
42
43
*
@@ -51,7 +52,8 @@ public FactoryBasedEnumDeserializer(Class<?> cls, AnnotatedMethod f, JavaType pa
51
52
_factory = f ;
52
53
_hasArgs = true ;
53
54
// We'll skip case of `String`, as well as no type (zero-args):
54
- _inputType = paramType .hasRawClass (String .class ) ? null : paramType ;
55
+ _inputType = (paramType .hasRawClass (String .class ) || paramType .hasRawClass (CharSequence .class ))
56
+ ? null : paramType ;
55
57
_deser = null ;
56
58
_valueInstantiator = valueInstantiator ;
57
59
_creatorProps = creatorProps ;
@@ -88,6 +90,9 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
88
90
BeanProperty property )
89
91
throws JsonMappingException
90
92
{
93
+ // So: no need to fetch if we had it; or if target is `String`(-like); or
94
+ // if we have properties-based Creator (for which we probably SHOULD do
95
+ // different contextualization?)
91
96
if ((_deser == null ) && (_inputType != null ) && (_creatorProps == null )) {
92
97
return new FactoryBasedEnumDeserializer (this ,
93
98
ctxt .findContextualValueDeserializer (_inputType , property ));
@@ -116,11 +121,14 @@ public LogicalType logicalType() {
116
121
public Object deserialize (JsonParser p , DeserializationContext ctxt ) throws IOException
117
122
{
118
123
Object value ;
124
+
125
+ // First: the case of having deserializer for non-String input for delegating
126
+ // Creator method
119
127
if (_deser != null ) {
120
128
value = _deser .deserialize (p , ctxt );
121
- } else if (_hasArgs ) {
122
- JsonToken curr = p .currentToken ();
123
129
130
+ // Second: property- and delegating-creators
131
+ } else if (_hasArgs ) {
124
132
// 30-Mar-2020, tatu: For properties-based one, MUST get JSON Object (before
125
133
// 2.11, was just assuming match)
126
134
if (_creatorProps != null ) {
@@ -138,15 +146,9 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
138
146
return deserializeEnumUsingPropertyBased (p , ctxt , _propCreator );
139
147
}
140
148
141
- // 30-Mar-2020, tatu: Single-arg delegating creators may go through
142
- // here; although not 100% sure why they do not take the first branch
143
- if (curr == JsonToken .VALUE_STRING || curr == JsonToken .FIELD_NAME ) {
144
- value = p .getText ();
145
- } else if (curr == JsonToken .VALUE_NUMBER_INT ) {
146
- value = p .getNumberValue ();
147
- } else {
148
- value = p .getValueAsString ();
149
- }
149
+ // 12-Oct-2021, tatu: We really should only get here if and when String
150
+ // value is expected; otherwise Deserializer should have been used earlier
151
+ value = p .getValueAsString ();
150
152
} else { // zero-args; just skip whatever value there may be
151
153
p .skipChildren ();
152
154
try {
@@ -160,10 +162,13 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
160
162
return _factory .callOnWith (_valueClass , value );
161
163
} catch (Exception e ) {
162
164
Throwable t = ClassUtil .throwRootCauseIfIOE (e );
163
- // [databind#1642]:
164
- if (ctxt .isEnabled (DeserializationFeature .READ_UNKNOWN_ENUM_VALUES_AS_NULL ) &&
165
- t instanceof IllegalArgumentException ) {
166
- return null ;
165
+ if (t instanceof IllegalArgumentException ) {
166
+ // [databind#1642]:
167
+ if (ctxt .isEnabled (DeserializationFeature .READ_UNKNOWN_ENUM_VALUES_AS_NULL )) {
168
+ return null ;
169
+ }
170
+ // 12-Oct-2021, tatu: Should probably try to provide better exception since
171
+ // we likely hit argument incompatibility... Or can this happen?
167
172
}
168
173
return ctxt .handleInstantiationProblem (_valueClass , value , t );
169
174
}
0 commit comments