Skip to content

Commit 1a5c144

Browse files
committed
Merge branch '2.16'
2 parents 9428f11 + 9f07a46 commit 1a5c144

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

release-notes/CREDITS-2.x

+7
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,13 @@ Antti Lampinen (arlampin@github)
16591659
* Reported #3897: 2.15.0 breaks deserialization when POJO/Record only has a single field
16601660
and is marked `Access.WRITE_ONLY`
16611661
(2.15.1)
1662+
* Reported #3897: 2.15.0 breaks deserialization when POJO/Record only has a single field
1663+
and is marked `Access.WRITE_ONLY`
1664+
(2.15.1)
1665+
1666+
Dmitry Bolotin (dbolotin@github)
1667+
* Reported #1172: `@JsonView` doesn't work with `@JsonCreator`
1668+
(2.15.4)
16621669

16631670
Kevin Baes (BaesKevin@github)
16641671
* Reported #3251: Generic class with generic field of runtime type `Double` is deserialized

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ Project: jackson-databind
9696
#4159: Add new `DefaultTyping.NON_FINAL_AND_ENUMS` to allow Default Typing for `Enum`s
9797
(contributed by Joo-Hyuk K)
9898

99+
2.15.4 (not yet released)
100+
101+
#1172: `@JsonView` doesn't work with `@JsonCreator`
102+
(reported by Dmitry B)
103+
99104
2.15.3 (12-Oct-2023)
100105
101106
#3968: Records with additional constructors failed to deserialize
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package tools.jackson.databind.views;
2+
3+
import com.fasterxml.jackson.annotation.*;
4+
5+
import tools.jackson.databind.*;
6+
7+
public class ViewsWithCreatorTest
8+
extends BaseMapTest
9+
{
10+
static class View { }
11+
static class View1 extends View { }
12+
static class View2 extends View { }
13+
14+
@JsonAutoDetect(
15+
fieldVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
16+
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
17+
getterVisibility = JsonAutoDetect.Visibility.NONE)
18+
@JsonIgnoreProperties(ignoreUnknown = true)
19+
static class ObjWithCreator {
20+
21+
public String a;
22+
23+
@JsonView(View1.class)
24+
public String b;
25+
26+
@JsonView(View2.class)
27+
public String c;
28+
29+
public ObjWithCreator() { }
30+
31+
@JsonCreator
32+
public ObjWithCreator(@JsonProperty("a") String a, @JsonProperty("b") String b, @JsonProperty("c") String c) {
33+
this.a = a;
34+
this.b = b;
35+
this.c = c;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return String.format("%s-%s-%s", a, b, c);
41+
}
42+
}
43+
44+
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
45+
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
46+
getterVisibility = JsonAutoDetect.Visibility.NONE)
47+
@JsonIgnoreProperties(ignoreUnknown = true)
48+
static class ObjWithoutCreator {
49+
50+
public String a;
51+
52+
@JsonView(View1.class)
53+
public String b;
54+
55+
@JsonView(View2.class)
56+
public String c;
57+
58+
public ObjWithoutCreator() { }
59+
60+
public ObjWithoutCreator(String a, String b, String c) {
61+
this.a = a;
62+
this.b = b;
63+
this.c = c;
64+
}
65+
66+
@Override
67+
public String toString() {
68+
return String.format("%s-%s-%s", a, b, c);
69+
}
70+
}
71+
72+
private final ObjectMapper MAPPER = newJsonMapper();
73+
74+
// [databind#1172]
75+
public void testWithJsonCreator() throws Exception
76+
{
77+
ObjectReader reader = MAPPER.readerFor(ObjWithCreator.class).withView(View1.class);
78+
79+
// serialize first,
80+
String json = MAPPER.writeValueAsString(new ObjWithCreator("a", "b", "c"));
81+
// then back
82+
assertEquals("a-b-null", reader.readValue(json).toString());
83+
}
84+
85+
// [databind#1172]
86+
public void testWithoutJsonCreator() throws Exception
87+
{
88+
ObjectReader reader = MAPPER.readerFor(ObjWithoutCreator.class).withView(View1.class);
89+
90+
// serialize first,
91+
String json = MAPPER.writeValueAsString(new ObjWithoutCreator("a", "b", "c"));
92+
// then back
93+
assertEquals("a-b-null", reader.readValue(json).toString());
94+
}
95+
}

0 commit comments

Comments
 (0)