Skip to content

Commit b3139d5

Browse files
committed
Add a test related to core/700, fix a minor problem in Map deserialization for "untyped"
1 parent 03d49f8 commit b3139d5

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/std/UntypedObjectDeserializer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ protected Object mapArray(JsonParser p, DeserializationContext ctxt,
492492
protected Object mapObject(JsonParser p, DeserializationContext ctxt) throws IOException
493493
{
494494
String key1;
495-
496495
JsonToken t = p.currentToken();
497496

498497
if (t == JsonToken.START_OBJECT) {
@@ -802,7 +801,6 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt, Object into
802801
if (_nonMerging) {
803802
return deserialize(p, ctxt);
804803
}
805-
806804
switch (p.currentTokenId()) {
807805
case JsonTokenId.ID_END_OBJECT:
808806
case JsonTokenId.ID_END_ARRAY:
@@ -920,7 +918,8 @@ protected Object[] mapArrayToArray(JsonParser p, DeserializationContext ctxt) th
920918
protected Object mapObject(JsonParser p, DeserializationContext ctxt) throws IOException
921919
{
922920
// will point to FIELD_NAME at this point, guaranteed
923-
String key1 = p.getText();
921+
// 19-Jul-2021, tatu: Was incorrectly using "getText()" before 2.13, fixed for 2.13.0
922+
String key1 = p.currentName();
924923
p.nextToken();
925924
Object value1 = deserialize(p, ctxt);
926925

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.fasterxml.jackson.databind.deser.filter;
2+
3+
import java.util.Collections;
4+
import java.util.Map;
5+
6+
import com.fasterxml.jackson.core.*;
7+
import com.fasterxml.jackson.core.filter.FilteringParserDelegate;
8+
import com.fasterxml.jackson.core.filter.TokenFilter;
9+
import com.fasterxml.jackson.databind.*;
10+
11+
public class ParserFilterViaMapTest extends BaseMapTest
12+
{
13+
private final ObjectMapper MAPPER = newJsonMapper();
14+
15+
static class NoTypeFilter extends TokenFilter {
16+
@Override
17+
public TokenFilter includeProperty(String name) {
18+
if ("@type".equals(name)) {
19+
return null;
20+
}
21+
return this;
22+
}
23+
}
24+
25+
// From [core#700], to verify at databind level
26+
// (and actually found a bug in doing so -- fixed for 2.13.0)
27+
public void testSimplePropertyExcludeFilter() throws Exception
28+
{
29+
final String json = "{\"@type\":\"xxx\",\"a\":{\"@type\":\"yyy\",\"b\":11}}";
30+
try (JsonParser p = new FilteringParserDelegate(
31+
MAPPER.createParser(json),
32+
new NoTypeFilter(),
33+
TokenFilter.Inclusion.INCLUDE_ALL_AND_PATH,
34+
true)) {
35+
Map<?,?> map = MAPPER.readValue(p, Map.class);
36+
Map<String, Object> EXP = Collections.singletonMap("a",
37+
Collections.singletonMap("b", Integer.valueOf(11)));
38+
assertEquals(EXP, map);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)