Skip to content

Commit 81b64d0

Browse files
committed
Merge branch '2.15' into 2.16
2 parents f72c3e0 + 3035c34 commit 81b64d0

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

release-notes/VERSION-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ Project: jackson-databind
109109

110110
#1172: `@JsonView` doesn't work with `@JsonCreator`
111111
(reported by Dmitry B)
112+
#4185: `@JsonIgnoreProperties` with `@JsonTypeInfo(include = JsonTypeInfo.As.EXTERNAL_PROPERTY)`
113+
does not work
114+
(reported by @jonasho)
115+
(fix contributed by Joo-Hyuk K)
112116
113117
2.15.3 (12-Oct-2023)
114118

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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,5 +361,4 @@ public static String q(String str) {
361361
public static String a2q(String json) {
362362
return json.replace("'", "\"");
363363
}
364-
365364
}
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)