Skip to content

Commit 066369f

Browse files
authored
Fix for 4185 (#4189)
1 parent 866f95f commit 066369f

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public abstract class BeanDeserializerBase
186186
protected UnwrappedPropertyHandler _unwrappedPropertyHandler;
187187

188188
/**
189-
* Handler that we need iff any of properties uses external
189+
* Handler that we need if any of properties uses external
190190
* type id.
191191
*/
192192
protected ExternalTypeHandler _externalTypeIdHandler;
@@ -292,6 +292,8 @@ protected BeanDeserializerBase(BeanDeserializerBase src, boolean ignoreAllUnknow
292292
_serializationShape = src._serializationShape;
293293

294294
_vanillaProcessing = src._vanillaProcessing;
295+
296+
_externalTypeIdHandler = src._externalTypeIdHandler;
295297
}
296298

297299
protected BeanDeserializerBase(BeanDeserializerBase src, NameTransformer unwrapper)
@@ -332,6 +334,8 @@ protected BeanDeserializerBase(BeanDeserializerBase src, NameTransformer unwrapp
332334

333335
// probably adds a twist, so:
334336
_vanillaProcessing = false;
337+
338+
_externalTypeIdHandler = src._externalTypeIdHandler;
335339
}
336340

337341
public BeanDeserializerBase(BeanDeserializerBase src, ObjectIdReader oir)
@@ -371,6 +375,8 @@ public BeanDeserializerBase(BeanDeserializerBase src, ObjectIdReader oir)
371375
_beanProperties = src._beanProperties.withProperty(idProp);
372376
_vanillaProcessing = false;
373377
}
378+
379+
_externalTypeIdHandler = src._externalTypeIdHandler;
374380
}
375381

376382
/**
@@ -405,6 +411,8 @@ public BeanDeserializerBase(BeanDeserializerBase src,
405411
// 01-May-2016, tatu: [databind#1217]: Remove properties from mapping,
406412
// to avoid them being deserialized
407413
_beanProperties = src._beanProperties.withoutProperties(ignorableProps, includableProps);
414+
415+
_externalTypeIdHandler = src._externalTypeIdHandler;
408416
}
409417

410418
/**
@@ -435,6 +443,8 @@ protected BeanDeserializerBase(BeanDeserializerBase src, BeanPropertyMap beanPro
435443
_serializationShape = src._serializationShape;
436444

437445
_vanillaProcessing = src._vanillaProcessing;
446+
447+
_externalTypeIdHandler = src._externalTypeIdHandler;
438448
}
439449

440450
@Deprecated // since 2.12

src/test/java/com/fasterxml/jackson/databind/BaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ public String quote(String str) {
441441
return q(str);
442442
}
443443

444-
protected static String a2q(String json) {
444+
public static String a2q(String json) {
445445
return json.replace("'", "\"");
446446
}
447447

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.fasterxml.jackson.databind.jsontype.ext;
2+
3+
import static com.fasterxml.jackson.databind.BaseMapTest.newJsonMapper;
4+
import static com.fasterxml.jackson.databind.BaseTest.a2q;
5+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
6+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
7+
import com.fasterxml.jackson.annotation.JsonSubTypes;
8+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
9+
import com.fasterxml.jackson.databind.ObjectMapper;
10+
import org.junit.jupiter.api.Test;
11+
12+
/**
13+
* Unit test to verify that the following issue is fixed:
14+
* [databind#4185]: @JsonIgnoreProperties with JsonTypeInfo.As.EXTERNAL_PROPERTY does not work
15+
*/
16+
class ExternalTypeIdWithJsonIgnore4185Test
17+
{
18+
19+
static class Parent {
20+
@JsonIgnoreProperties("parent")
21+
public Child child;
22+
}
23+
24+
static class Child {
25+
public Parent parent;
26+
public String childType;
27+
28+
@JsonTypeInfo(
29+
use = JsonTypeInfo.Id.NAME,
30+
include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
31+
property = "childType"
32+
)
33+
@JsonSubTypes({
34+
@JsonSubTypes.Type(name = "A", value = SubChildA.class),
35+
@JsonSubTypes.Type(name = "B", value = SubChildB.class),
36+
})
37+
public SubChild subChild;
38+
}
39+
40+
interface SubChild { }
41+
static class SubChildA implements SubChild { }
42+
static class SubChildB implements SubChild { }
43+
44+
private final ObjectMapper MAPPER = newJsonMapper();
45+
46+
@Test
47+
public void testDeserialization() throws Exception
48+
{
49+
Parent parent = MAPPER.readValue(
50+
a2q("{'child': {'childType': 'A', 'subChild':{} } }"),
51+
Parent.class);
52+
53+
assertInstanceOf(SubChildA.class, parent.child.subChild);
54+
}
55+
}

0 commit comments

Comments
 (0)