Skip to content

Commit ae7ad13

Browse files
committed
Merge branch '2.19'
2 parents 983b635 + 25e1135 commit ae7ad13

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ Project: jackson-databind
8383
(contributed by @pjfanning)
8484
#5052: Minor bug in `FirstCharBasedValidator.forFirstNameRule()`: returns `null`
8585
in non-default case
86+
#5069: Add copy-constructor for `MappingIterator`
87+
(contributed by @wrongwrong)
8688
8789
2.18.3 (28-Feb-2025)
8890

src/main/java/tools/jackson/databind/MappingIterator.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ protected MappingIterator(JavaType type, JsonParser p, DeserializationContext ct
165165
}
166166
}
167167

168+
/**
169+
* Copy-constructor that sub-classes can use when creating new instances
170+
* by fluent-style construction.
171+
*
172+
* @since 2.19
173+
*/
174+
protected MappingIterator(MappingIterator<T> src) {
175+
this(src._type, src._parser, src._context, src._deserializer, src._closeParser, src._updatedValue);
176+
}
177+
168178
/**
169179
* Method for getting an "empty" iterator instance: one that never
170180
* has more values; may be freely shared.

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

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

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

@@ -97,7 +97,10 @@ public void testSerializeReadOnlyNamedProperty() throws Exception {
9797
public void testDeserializeReadOnlyNamedProperty() throws Exception {
9898
RecordWithReadOnlyNamedProperty value = MAPPER.readValue(a2q("{'id':123,'name':'Bob'}"),
9999
RecordWithReadOnlyNamedProperty.class);
100-
assertEquals(new RecordWithReadOnlyNamedProperty(123, "Bob"), value); // BUG: should be `null` instead of "Bob"
100+
101+
// BUG: should be `null` instead of "Bob"
102+
// 01-Apr-2025, tatu: Should be in "tofix", then?
103+
assertEquals(new RecordWithReadOnlyNamedProperty(123, "Bob"), value);
101104
}
102105

103106
/*
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package tools.jackson.databind.records.tofix;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
import tools.jackson.databind.ObjectMapper;
8+
import tools.jackson.databind.testutil.DatabindTestUtil;
9+
import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected;
10+
11+
import static org.junit.jupiter.api.Assertions.assertNotNull;
12+
import static org.junit.jupiter.api.Assertions.assertNull;
13+
14+
public class RecordWithReadOnly5049Test extends DatabindTestUtil
15+
{
16+
record ReadOnly5049Record(
17+
@JsonProperty(value = "a", access = JsonProperty.Access.READ_ONLY) String a,
18+
@JsonProperty(value = "b", access = JsonProperty.Access.READ_ONLY) String b) {
19+
}
20+
21+
static class ReadOnly5049Pojo
22+
{
23+
protected String a, b;
24+
25+
ReadOnly5049Pojo(
26+
@JsonProperty(value = "a", access = JsonProperty.Access.READ_ONLY) String a,
27+
@JsonProperty(value = "b", access = JsonProperty.Access.READ_ONLY) String b) {
28+
this.a = a;
29+
this.b = b;
30+
}
31+
32+
public String getA() { return a; }
33+
public String getB() { return b; }
34+
}
35+
36+
private final ObjectMapper MAPPER = newJsonMapper();
37+
38+
@Test
39+
void testRoundtripPOJO() throws Exception
40+
{
41+
String json = MAPPER.writeValueAsString(new ReadOnly5049Pojo("hello", "world"));
42+
//System.err.println("JSON/pojo: "+json);
43+
ReadOnly5049Pojo pojo = MAPPER.readerFor(ReadOnly5049Pojo.class).readValue(json);
44+
assertNotNull(pojo);
45+
assertNull(pojo.a);
46+
assertNull(pojo.b);
47+
}
48+
49+
@JacksonTestFailureExpected
50+
@Test
51+
void testRoundtripRecord() throws Exception
52+
{
53+
// json = MAPPER.writeValueAsString(new ReadOnly5049Record("hello", "world"));
54+
String json = "{\"a\":\"hello\",\"b\":\"world\"}";
55+
ReadOnly5049Record record = MAPPER.readValue(json, ReadOnly5049Record.class);
56+
assertNotNull(record);
57+
assertNull(record.a());
58+
assertNull(record.b());
59+
}
60+
}

0 commit comments

Comments
 (0)