Skip to content

Commit d4977d3

Browse files
committed
Merge branch '2.19' into 3.x
2 parents 9f07e26 + b7ac1f0 commit d4977d3

File tree

6 files changed

+37
-62
lines changed

6 files changed

+37
-62
lines changed

release-notes/CREDITS-2.x

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,10 +1889,13 @@ Zhen Lin Low (@zhenlin-pay2)
18891889
when collecting bean properties, breaking AsExternalTypeDeserializer
18901890
(2.18.3)
18911891

1892-
Fawzi Essam (@iifawz)
1892+
Fawzi Essam (@iifawzi)
1893+
* Contributed fix or #4628: `@JsonIgnore` and `@JsonProperty.access=READ_ONLY`
1894+
on Record property
1895+
(2.18.4)
18931896
* Contributed fix for #5049: Duplicate creator property "b" (index 0 vs 1)
18941897
on simple java record
1895-
(2.18.3)
1898+
(2.18.4)
18961899

18971900
Liam Feid (@fxshlein)
18981901
* Contributed #1467: Support `@JsonUnwrapped` with `@JsonCreator`

release-notes/VERSION-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ Project: jackson-databind
9292
9393
2.18.4 (not yet released)
9494
95+
#4628: `@JsonIgnore` and `@JsonProperty.access=READ_ONLY` on Record property
96+
ignored for deserialization
97+
(reported by Sim Y-T)
98+
(fix contributed by Fawzi E)
9599
#5049: Duplicate creator property "b" (index 0 vs 1) on simple java record
96100
(reported by @richard-melvin)
97101
(fix contributed by Fawzi E)

src/main/java/tools/jackson/databind/introspect/POJOPropertiesCollector.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,12 @@ protected void _renameProperties(Map<String, POJOPropertyBuilder> props)
13421342
Map.Entry<String, POJOPropertyBuilder> entry = it.next();
13431343
POJOPropertyBuilder prop = entry.getValue();
13441344

1345+
// 10-Apr-2025: [databind#4628] skip properties that are marked to be ignored
1346+
// TODO: we are using implicit name, is that ok?
1347+
if (_ignoredPropertyNames != null && _ignoredPropertyNames.contains(prop.getName())) {
1348+
continue;
1349+
}
1350+
13451351
Collection<PropertyName> l = prop.findExplicitNames();
13461352

13471353
// no explicit names? Implicit one is fine as is

src/test/java/tools/jackson/databind/records/RecordJsonSerDeser188Test.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public void serialize(String value, JsonGenerator jgen, SerializationContext pro
4646
@SuppressWarnings("serial")
4747
static class PrefixStringDeserializer extends StdScalarDeserializer<String>
4848
{
49+
private static final long serialVersionUID = 1L;
50+
4951
protected PrefixStringDeserializer() {
5052
super(String.class);
5153
}

src/test/java/tools/jackson/databind/records/RecordWithJsonIgnoreTest.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ record RecordWithIgnore(int id, @JsonIgnore String name) {
1919
record RecordWithIgnoreJsonProperty(int id, @JsonIgnore @JsonProperty("name") String name) {
2020
}
2121

22+
record RecordWithIgnoreJsonPropertyDifferentName(int id, @JsonIgnore @JsonProperty("name2") String name) {
23+
}
24+
2225
record RecordWithIgnoreAccessor(int id, String name) {
23-
2426
@JsonIgnore
2527
@Override
2628
public String name() {
@@ -64,6 +66,20 @@ public void testSerializeJsonIgnoreAndJsonPropertyRecord() throws Exception {
6466
assertEquals("{\"id\":123}", json);
6567
}
6668

69+
@Test
70+
public void testDeserializeJsonIgnoreAndJsonPropertyRecord() throws Exception {
71+
RecordWithIgnoreJsonProperty value = MAPPER.readValue("{\"id\":123,\"name\":\"Bob\"}",
72+
RecordWithIgnoreJsonProperty.class);
73+
assertEquals(new RecordWithIgnoreJsonProperty(123, null), value);
74+
}
75+
76+
@Test
77+
public void testDeserializeJsonIgnoreRecordWithDifferentName() throws Exception {
78+
RecordWithIgnoreJsonPropertyDifferentName value = MAPPER.readValue("{\"id\":123,\"name\":\"Bob\"}",
79+
RecordWithIgnoreJsonPropertyDifferentName.class);
80+
assertEquals(new RecordWithIgnoreJsonPropertyDifferentName(123, null), value);
81+
}
82+
6783
/*
6884
/**********************************************************************
6985
/* Test methods, JsonIgnore accessor
@@ -72,10 +88,11 @@ public void testSerializeJsonIgnoreAndJsonPropertyRecord() throws Exception {
7288

7389
@Test
7490
public void testSerializeJsonIgnoreAccessorRecord() throws Exception {
75-
String json = MAPPER.writeValueAsString(new RecordWithIgnoreAccessor(123, "Bob"));
76-
assertEquals("{\"id\":123}", json);
91+
assertEquals("{\"id\":123}",
92+
MAPPER.writeValueAsString(new RecordWithIgnoreAccessor(123, "Bob")));
7793
}
7894

95+
// [databind#4628]
7996
@Test
8097
public void testDeserializeJsonIgnoreAccessorRecord() throws Exception {
8198
RecordWithIgnoreAccessor expected = new RecordWithIgnoreAccessor(123, null);

src/test/java/tools/jackson/databind/records/tofix/RecordWIthJsonIgnoreAndValue4628Test.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)