Skip to content

Commit de53cb5

Browse files
committed
Add passing test for #4678
1 parent 9691f87 commit de53cb5

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

release-notes/CREDITS-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,3 +1823,7 @@ Eduard Gomoliako (Gems@github)
18231823
* Reported #4602: Possible wrong use of _arrayDelegateDeserializer in
18241824
BeanDeserializerBase::deserializeFromObjectUsingNonDefault()
18251825
(2.18.0)
1826+
1827+
Mathijs Vogelzang (mathijs81@github)
1828+
* Reported #4678: Java records don't serialize with `MapperFeature.REQUIRE_SETTERS_FOR_GETTERS`
1829+
(2.18.0)

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Project: jackson-databind
6868
#4634: `@JsonAnySetter` not working when annotated on both constructor
6969
parameter & field
7070
(contributed by Sim Y-T)
71+
#4678: Java records don't serialize with `MapperFeature.REQUIRE_SETTERS_FOR_GETTERS`
72+
(reported by Mathijs V)
7173
7274
2.17.2 (05-Jul-2024)
7375

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,23 @@ public void testDeserialize_AllWriteOnlyParameter() throws Exception {
291291
assertEquals(new RecordAllWriteOnly(123, "Bob", "bob@example.com"), value);
292292
}
293293

294+
/*
295+
/**********************************************************************
296+
/* Test method(s), MapperFeature.REQUIRE_SETTERS_FOR_GETTERS
297+
/**********************************************************************
298+
*/
299+
300+
// [databind#4678]
301+
@Test
302+
public void testSerializeWithSettersForGetters() throws Exception {
303+
ObjectMapper mapperWithSetters = JsonMapper.builder()
304+
.configure(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS, true)
305+
.build();
306+
var input = new SimpleRecord(123, "Bob");
307+
assertEquals(MAPPER.writeValueAsString(input),
308+
mapperWithSetters.writeValueAsString(input));
309+
}
310+
294311
/*
295312
/**********************************************************************
296313
/* Internal helper methods

0 commit comments

Comments
 (0)