Skip to content

Commit 9f07a46

Browse files
committed
Merge branch '2.15' into 2.16
2 parents 1aaa165 + 0dfae66 commit 9f07a46

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-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,97 @@
1+
package com.fasterxml.jackson.databind.views;
2+
3+
import com.fasterxml.jackson.annotation.*;
4+
5+
import com.fasterxml.jackson.databind.BaseMapTest;
6+
import com.fasterxml.jackson.databind.ObjectMapper;
7+
import com.fasterxml.jackson.databind.ObjectReader;
8+
9+
public class ViewsWithCreatorTest
10+
extends BaseMapTest
11+
{
12+
static class View { }
13+
static class View1 extends View { }
14+
static class View2 extends View { }
15+
16+
@JsonAutoDetect(
17+
fieldVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
18+
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
19+
getterVisibility = JsonAutoDetect.Visibility.NONE)
20+
@JsonIgnoreProperties(ignoreUnknown = true)
21+
static class ObjWithCreator {
22+
23+
public String a;
24+
25+
@JsonView(View1.class)
26+
public String b;
27+
28+
@JsonView(View2.class)
29+
public String c;
30+
31+
public ObjWithCreator() { }
32+
33+
@JsonCreator
34+
public ObjWithCreator(@JsonProperty("a") String a, @JsonProperty("b") String b, @JsonProperty("c") String c) {
35+
this.a = a;
36+
this.b = b;
37+
this.c = c;
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return String.format("%s-%s-%s", a, b, c);
43+
}
44+
}
45+
46+
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
47+
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
48+
getterVisibility = JsonAutoDetect.Visibility.NONE)
49+
@JsonIgnoreProperties(ignoreUnknown = true)
50+
static class ObjWithoutCreator {
51+
52+
public String a;
53+
54+
@JsonView(View1.class)
55+
public String b;
56+
57+
@JsonView(View2.class)
58+
public String c;
59+
60+
public ObjWithoutCreator() { }
61+
62+
public ObjWithoutCreator(String a, String b, String c) {
63+
this.a = a;
64+
this.b = b;
65+
this.c = c;
66+
}
67+
68+
@Override
69+
public String toString() {
70+
return String.format("%s-%s-%s", a, b, c);
71+
}
72+
}
73+
74+
private final ObjectMapper MAPPER = newJsonMapper();
75+
76+
// [databind#1172]
77+
public void testWithJsonCreator() throws Exception
78+
{
79+
ObjectReader reader = MAPPER.readerFor(ObjWithCreator.class).withView(View1.class);
80+
81+
// serialize first,
82+
String json = MAPPER.writeValueAsString(new ObjWithCreator("a", "b", "c"));
83+
// then back
84+
assertEquals("a-b-null", reader.readValue(json).toString());
85+
}
86+
87+
// [databind#1172]
88+
public void testWithoutJsonCreator() throws Exception
89+
{
90+
ObjectReader reader = MAPPER.readerFor(ObjWithoutCreator.class).withView(View1.class);
91+
92+
// serialize first,
93+
String json = MAPPER.writeValueAsString(new ObjWithoutCreator("a", "b", "c"));
94+
// then back
95+
assertEquals("a-b-null", reader.readValue(json).toString());
96+
}
97+
}

0 commit comments

Comments
 (0)