Skip to content

Commit 09fca79

Browse files
authored
Fix #5891: property-based EnumMap parsing after skipped unknown enum keys (#5892)
1 parent 37e1424 commit 09fca79

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

release-notes/CREDITS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ Lee Jiwon (@dlwldnjs1009)
215215
* Fixed #5867: Fix `Map.Entry` deserialization for property-level
216216
`Shape.NATURAL` override
217217
[3.1.2]
218-
* Fixed #5870: `EnumMap` and `EnumSet` properties ignore `@JsonDeserialize(contentConverter)`
218+
* Fixed #5870: `EnumMap` and `EnumSet` properties ignore `@JsonDeserialize(contentConverter)`
219+
[3.1.2]
220+
* Fixed #5891: `EnumMapDeserializer._deserializeUsingProperties()` corrupts parser
221+
state after skipping unknown enum keys
219222
[3.1.2]
220223

221224
Garret Wilson (@garretwilson)

release-notes/VERSION

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ No changes since 3.1
2828
on another property
2929
(reported by Aleksandr G)
3030
(fix by @cowtowncoder, w/ Claude code)
31+
#5891: `EnumMapDeserializer._deserializeUsingProperties()` corrupts parser
32+
state after skipping unknown enum keys
33+
(fixed by Lee Jiwon)
3134

3235
3.1.1 (27-Mar-2026)
3336

src/main/java/tools/jackson/databind/deser/jdk/EnumMapDeserializer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ public EnumMap<?,?> _deserializeUsingProperties(JsonParser p, DeserializationCon
373373
}
374374
// 24-Mar-2012, tatu: Null won't work as a key anyway, so let's
375375
// just skip the entry then. But we must skip the value as well, if so.
376-
p.nextToken();
377376
p.skipChildren();
378377
continue;
379378
}

src/test/java/tools/jackson/databind/deser/enums/EnumMapDeserializationTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,33 @@ public void testCustomEnumMapFromProps() throws Exception
190190
assertEquals(2, map.size());
191191
}
192192

193+
// [databind#5891]: extra p.nextToken() in _deserializeUsingProperties()
194+
// corrupts parser state when skipping unknown enum key
195+
@Test
196+
public void testUnknownKeyAsNullWithPropertyBasedCreator() throws Exception
197+
{
198+
ObjectReader r = MAPPER.readerFor(FromPropertiesEnumMap.class)
199+
.with(EnumFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL);
200+
201+
_verifyFromPropertiesEnumMap(r.readValue(a2q(
202+
"{'NOPE':'skip','a':13,'RULES':'jackson','b':-731,'OK':'yes'}")));
203+
204+
// Unknown-key values are skipped before deserializing into EnumMap<String>.
205+
_verifyFromPropertiesEnumMap(r.readValue(a2q(
206+
"{'NOPE':{'nested':'value'},'a':13,'RULES':'jackson','b':-731,'OK':'yes'}")));
207+
_verifyFromPropertiesEnumMap(r.readValue(a2q(
208+
"{'NOPE':[1,2,3],'a':13,'RULES':'jackson','b':-731,'OK':'yes'}")));
209+
}
210+
211+
private void _verifyFromPropertiesEnumMap(FromPropertiesEnumMap map)
212+
{
213+
assertEquals(13, map.a0);
214+
assertEquals(-731, map.b0);
215+
assertEquals("jackson", map.get(TestEnum.RULES));
216+
assertEquals("yes", map.get(TestEnum.OK));
217+
assertEquals(2, map.size());
218+
}
219+
193220
/*
194221
/**********************************************************
195222
/* Test methods: polymorphic

0 commit comments

Comments
 (0)