Skip to content

Commit b7ac1f0

Browse files
committed
Merge branch '2.18' into 2.19
2 parents e33c764 + 15d0309 commit b7ac1f0

File tree

6 files changed

+37
-60
lines changed

6 files changed

+37
-60
lines changed

release-notes/CREDITS-2.x

+5-2
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

+4
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/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java

+6
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,12 @@ protected void _renameProperties(Map<String, POJOPropertyBuilder> props)
13901390
Map.Entry<String, POJOPropertyBuilder> entry = it.next();
13911391
POJOPropertyBuilder prop = entry.getValue();
13921392

1393+
// 10-Apr-2025: [databind#4628] skip properties that are marked to be ignored
1394+
// TODO: we are using implicit name, is that ok?
1395+
if (_ignoredPropertyNames != null && _ignoredPropertyNames.contains(prop.getName())) {
1396+
continue;
1397+
}
1398+
13931399
Collection<PropertyName> l = prop.findExplicitNames();
13941400

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

src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordJsonSerDeser188Test.java

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public void serialize(String value, JsonGenerator jgen, SerializerProvider provi
5151
@SuppressWarnings("serial")
5252
static class PrefixStringDeserializer extends StdScalarDeserializer<String>
5353
{
54+
private static final long serialVersionUID = 1L;
55+
5456
protected PrefixStringDeserializer() {
5557
super(String.class);
5658
}

src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithJsonIgnoreTest.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ record RecordWithIgnore(int id, @JsonIgnore String name) {
1818
record RecordWithIgnoreJsonProperty(int id, @JsonIgnore @JsonProperty("name") String name) {
1919
}
2020

21+
record RecordWithIgnoreJsonPropertyDifferentName(int id, @JsonIgnore @JsonProperty("name2") String name) {
22+
}
23+
2124
record RecordWithIgnoreAccessor(int id, String name) {
22-
2325
@JsonIgnore
2426
@Override
2527
public String name() {
@@ -63,6 +65,20 @@ public void testSerializeJsonIgnoreAndJsonPropertyRecord() throws Exception {
6365
assertEquals("{\"id\":123}", json);
6466
}
6567

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

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

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

src/test-jdk17/java/com/fasterxml/jackson/databind/tofix/RecordWIthJsonIgnoreAndValue4628Test.java

-55
This file was deleted.

0 commit comments

Comments
 (0)