Skip to content

Commit 64ff9b4

Browse files
committed
Add failing test for #5049
1 parent 13e3130 commit 64ff9b4

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
import static org.junit.jupiter.api.Assertions.assertEquals;
1212

13-
public class RecordWithReadOnlyTest extends DatabindTestUtil {
14-
13+
public class RecordWithReadOnlyTest extends DatabindTestUtil
14+
{
1515
record RecordWithReadOnly(int id, @JsonProperty(access = Access.READ_ONLY) String name) {
1616
}
1717

@@ -94,7 +94,10 @@ public void testSerializeReadOnlyNamedProperty() throws Exception {
9494
public void testDeserializeReadOnlyNamedProperty() throws Exception {
9595
RecordWithReadOnlyNamedProperty value = MAPPER.readValue(a2q("{'id':123,'name':'Bob'}"),
9696
RecordWithReadOnlyNamedProperty.class);
97-
assertEquals(new RecordWithReadOnlyNamedProperty(123, "Bob"), value); // BUG: should be `null` instead of "Bob"
97+
98+
// BUG: should be `null` instead of "Bob"
99+
// 01-Apr-2025, tatu: Should be in "tofix", then?
100+
assertEquals(new RecordWithReadOnlyNamedProperty(123, "Bob"), value);
98101
}
99102

100103
/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fasterxml.jackson.databind.tofix;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
9+
10+
import static org.junit.jupiter.api.Assertions.assertNotNull;
11+
12+
public class RecordWithReadOnly5049Test extends DatabindTestUtil
13+
{
14+
record ReadOnly5049(
15+
@JsonProperty(value = "a", access = JsonProperty.Access.READ_ONLY) String a,
16+
@JsonProperty(value = "b", access = JsonProperty.Access.READ_ONLY) String b) {
17+
}
18+
19+
private final ObjectMapper MAPPER = newJsonMapper();
20+
21+
@Test
22+
void testRoundtrip() throws Exception
23+
{
24+
String string = MAPPER.writeValueAsString(new ReadOnly5049 ("hello", "world"));
25+
assertNotNull(MAPPER.readerFor(ReadOnly5049.class).readValue(string));
26+
}
27+
}

0 commit comments

Comments
 (0)