Skip to content

Commit b666054

Browse files
committed
Merge branch '2.18' into 2.19
2 parents 701b8f0 + 2610a95 commit b666054

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,6 +3656,8 @@ public <T extends JsonNode> T valueToTree(Object fromValue)
36563656
* serializable)
36573657
*
36583658
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
3659+
* It is recommended to try directly testing serialization using actual JSON inputs and outputs
3660+
* in test cases to ensure correctness and compatibility with real-world use cases.
36593661
*/
36603662
@Deprecated // @since 2.18
36613663
public boolean canSerialize(Class<?> type) {
@@ -3670,6 +3672,8 @@ public boolean canSerialize(Class<?> type) {
36703672
* @since 2.3
36713673
*
36723674
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
3675+
* It is recommended to try directly testing serialization using actual JSON inputs and outputs
3676+
* in test cases to ensure correctness and compatibility with real-world use cases.
36733677
*/
36743678
@Deprecated // @since 2.18
36753679
public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause) {
@@ -3694,6 +3698,8 @@ public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause) {
36943698
* serializable)
36953699
*
36963700
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
3701+
* It is recommended to try directly testing deserialization using actual JSON inputs and outputs
3702+
* in test cases to ensure correctness and compatibility with real-world use cases.
36973703
*/
36983704
@Deprecated // @since 2.18
36993705
public boolean canDeserialize(JavaType type)
@@ -3710,6 +3716,8 @@ public boolean canDeserialize(JavaType type)
37103716
* @since 2.3
37113717
*
37123718
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
3719+
* It is recommended to try directly testing deserialization using actual JSON inputs and outputs
3720+
* in test cases to ensure correctness and compatibility with real-world use cases.
37133721
*/
37143722
@Deprecated // @since 2.18
37153723
public boolean canDeserialize(JavaType type, AtomicReference<Throwable> cause)

src/main/java/com/fasterxml/jackson/databind/ObjectWriter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,8 @@ public void acceptJsonFormatVisitor(Class<?> type, JsonFormatVisitorWrapper visi
12151215
* it could serialize an instance of given Class.
12161216
*
12171217
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
1218+
* It is recommended to try directly testing serialization using actual JSON inputs and outputs
1219+
* in test cases to ensure correctness and compatibility with real-world use cases.
12181220
*/
12191221
@Deprecated // @since 2.18
12201222
public boolean canSerialize(Class<?> type) {
@@ -1229,6 +1231,8 @@ public boolean canSerialize(Class<?> type) {
12291231
* @since 2.3
12301232
*
12311233
* @deprecated Since 2.18 use discouraged; method to be removed from Jackson 3.0
1234+
* It is recommended to try directly testing serialization using actual JSON inputs and outputs
1235+
* in test cases to ensure correctness and compatibility with real-world use cases.
12321236
*/
12331237
@Deprecated // @since 2.18
12341238
public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause) {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.fasterxml.jackson.databind.tofix;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import com.fasterxml.jackson.annotation.JsonCreator;
6+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
7+
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
import com.fasterxml.jackson.databind.ObjectMapper;
10+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
11+
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected;
12+
13+
import static org.junit.jupiter.api.Assertions.assertNotNull;
14+
15+
// [databind#3355] Deserialization fails depending on the order of deserialized
16+
// objects with "Cannot construct instance (although at least one Creator exists)"
17+
public class CreatorWithIgnoreProperties3355Test
18+
extends DatabindTestUtil
19+
{
20+
static class Common3355 {
21+
private final String property;
22+
private final ContainerFail3355 container;
23+
24+
@JsonCreator
25+
public Common3355(@JsonProperty("property") final String property,
26+
@JsonProperty("container") final ContainerFail3355 container) {
27+
this.property = property;
28+
this.container = container;
29+
}
30+
31+
public String getProperty() {
32+
return property;
33+
}
34+
35+
public ContainerFail3355 getContainer() {
36+
return container;
37+
}
38+
}
39+
40+
static class ContainerFail3355 {
41+
private final Common3355 common;
42+
43+
@JsonCreator
44+
public ContainerFail3355(@JsonProperty("common") final Common3355 common) {
45+
this.common = common;
46+
}
47+
48+
@JsonIgnoreProperties("container")
49+
public Common3355 getCommon() {
50+
return common;
51+
}
52+
}
53+
54+
private final ObjectMapper MAPPER = newJsonMapper();
55+
56+
@JacksonTestFailureExpected
57+
@Test
58+
public void testDeserFailing() throws Exception
59+
{
60+
final String objectJson = "{ \"property\": \"valueOne\" }";
61+
final String containersJson = "{ \"common\": { \"property\": \"valueTwo\" } }";
62+
63+
// If we deserialize inner object first, outer object FAILS
64+
Common3355 object = MAPPER.readValue(objectJson, Common3355.class);
65+
ContainerFail3355 container = MAPPER.readValue(containersJson, ContainerFail3355.class);
66+
67+
assertNotNull(object);
68+
assertNotNull(container);
69+
}
70+
71+
@Test
72+
public void testDeserPassing() throws Exception
73+
{
74+
final String objectJson = "{ \"property\": \"valueOne\" }";
75+
final String containersJson = "{ \"common\": { \"property\": \"valueTwo\" } }";
76+
77+
// If we deserialize outer object first, it WORKS
78+
final ContainerFail3355 container = MAPPER.readValue(containersJson, ContainerFail3355.class);
79+
final Common3355 object = MAPPER.readValue(objectJson, Common3355.class);
80+
81+
assertNotNull(object);
82+
assertNotNull(container);
83+
}
84+
}

0 commit comments

Comments
 (0)