Skip to content

Commit 9e89168

Browse files
committed
Test, logic fixes.
1 parent a1f41a4 commit 9e89168

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎src/main/java/tools/jackson/databind/ext/javatime/deser/MonthDeserializer.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,26 @@ public Month deserialize(JsonParser p, DeserializationContext ctxt)
9494
return (Month) ctxt.handleUnexpectedToken(getValueType(ctxt),
9595
JsonToken.START_ARRAY, p, "Cannot deserialize `Month` from empty JSON Array");
9696
}
97+
// Validate token shape before checking UNWRAP, so inputs like [true], [1.5]
98+
// or [{}] get a token-type diagnostic instead of a misleading suggestion to
99+
// enable UNWRAP_SINGLE_VALUE_ARRAYS (which would not help).
100+
if (t != JsonToken.VALUE_NUMBER_INT
101+
&& t != JsonToken.VALUE_STRING
102+
&& t != JsonToken.VALUE_EMBEDDED_OBJECT) {
103+
return _reportWrongToken(ctxt, JsonToken.VALUE_NUMBER_INT, Integer.class.getName());
104+
}
97105
if (!ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
98106
return (Month) ctxt.handleUnexpectedToken(getValueType(ctxt),
99107
JsonToken.START_ARRAY, p,
100108
"Cannot deserialize `Month` out of START_ARRAY token: enable `DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS`");
101109
}
102-
if ((t == JsonToken.VALUE_STRING || t == JsonToken.VALUE_EMBEDDED_OBJECT)) {
110+
if (t == JsonToken.VALUE_STRING || t == JsonToken.VALUE_EMBEDDED_OBJECT) {
103111
final Month parsed = deserialize(p, ctxt);
104112
if (p.nextToken() != JsonToken.END_ARRAY) {
105113
handleMissingEndArrayForSingle(p, ctxt);
106114
}
107115
return parsed;
108116
}
109-
if (t != JsonToken.VALUE_NUMBER_INT) {
110-
return _reportWrongToken(ctxt, JsonToken.VALUE_NUMBER_INT, Integer.class.getName());
111-
}
112117
int month = p.getIntValue();
113118
if (p.nextToken() != JsonToken.END_ARRAY) {
114119
throw ctxt.wrongTokenException(p, handledType(), JsonToken.END_ARRAY,

‎src/test/java/tools/jackson/databind/ext/javatime/deser/MonthDeserializerTest.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ public void testDeserializationAsArrayWithMoreThanOneElement() throws Exception
324324
@Test
325325
public void testDeserializationAsArrayWithWrongToken() throws Exception
326326
{
327-
// [databind#5957]: Boolean in array without UNWRAP should fail (UNWRAP check fires first)
327+
// [databind#5957]: Boolean is not a coercible token shape; report token-type mismatch
328328
assertError(
329329
() -> readerForOneBased().readValue("[true]"),
330330
MismatchedInputException.class,
331-
"UNWRAP_SINGLE_VALUE_ARRAYS"
331+
"Expected VALUE_NUMBER_INT"
332332
);
333333
}
334334

@@ -346,22 +346,22 @@ public void testDeserializationAsArrayWithStringUnwrapDisabled() throws Exceptio
346346
@Test
347347
public void testDeserializationAsArrayWithFloatUnwrapDisabled() throws Exception
348348
{
349-
// [databind#5957]: Float in array without UNWRAP should fail (UNWRAP check fires first)
349+
// [databind#5957]: Float is not a coercible token shape; report token-type mismatch
350350
assertError(
351351
() -> readerForOneBased().readValue("[1.5]"),
352352
MismatchedInputException.class,
353-
"UNWRAP_SINGLE_VALUE_ARRAYS"
353+
"Expected VALUE_NUMBER_INT"
354354
);
355355
}
356356

357357
@Test
358358
public void testDeserializationAsArrayWithObjectUnwrapDisabled() throws Exception
359359
{
360-
// [databind#5957]: Object in array without UNWRAP should fail (UNWRAP check fires first)
360+
// [databind#5957]: Object is not a coercible token shape; report token-type mismatch
361361
assertError(
362362
() -> readerForOneBased().readValue("[{}]"),
363363
MismatchedInputException.class,
364-
"UNWRAP_SINGLE_VALUE_ARRAYS"
364+
"Expected VALUE_NUMBER_INT"
365365
);
366366
}
367367

0 commit comments

Comments
 (0)