@@ -173,16 +173,15 @@ public LogicalType logicalType() {
173
173
@ Override
174
174
public Object deserialize (JsonParser p , DeserializationContext ctxt ) throws IOException
175
175
{
176
- String text ;
177
- JsonToken curr = p .currentToken ();
178
-
179
176
// Usually should just get string value:
180
177
// 04-Sep-2020, tatu: for 2.11.3 / 2.12.0, removed "FIELD_NAME" as allowed;
181
178
// did not work and gave odd error message.
182
- if (curr == JsonToken .VALUE_STRING ) {
183
- text = p .getText ();
179
+ if (p .hasToken (JsonToken .VALUE_STRING )) {
180
+ return _fromString (p , ctxt , p .getText ());
181
+ }
182
+
184
183
// But let's consider int acceptable as well (if within ordinal range)
185
- } else if (curr == JsonToken .VALUE_NUMBER_INT ) {
184
+ if (p . hasToken ( JsonToken .VALUE_NUMBER_INT ) ) {
186
185
// ... unless told not to do that
187
186
int index = p .getIntValue ();
188
187
if (ctxt .isEnabled (DeserializationFeature .FAIL_ON_NUMBERS_FOR_ENUMS )) {
@@ -203,13 +202,20 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
203
202
_enumsByIndex .length -1 );
204
203
}
205
204
return null ;
206
- } else if (curr == JsonToken .START_OBJECT ) {
207
- // 29-Jun-2020, tatu: New! "Scalar from Object" (mostly for XML)
208
- text = ctxt .extractScalarFromObject (p , this , _valueClass );
209
- } else {
210
- return _deserializeOther (p , ctxt );
211
205
}
212
206
207
+ // 29-Jun-2020, tatu: New! "Scalar from Object" (mostly for XML)
208
+ if (p .isExpectedStartObjectToken ()) {
209
+ return _fromString (p , ctxt ,
210
+ ctxt .extractScalarFromObject (p , this , _valueClass ));
211
+ }
212
+ return _deserializeOther (p , ctxt );
213
+ }
214
+
215
+ protected Object _fromString (JsonParser p , DeserializationContext ctxt ,
216
+ String text )
217
+ throws IOException
218
+ {
213
219
CompactStringObjectMap lookup = ctxt .isEnabled (DeserializationFeature .READ_ENUMS_USING_TO_STRING )
214
220
? _getToStringLookup (ctxt ) : _lookupByName ;
215
221
Object result = lookup .find (text );
0 commit comments