Skip to content

Commit 3f55434

Browse files
committed
Mark #4119 as fixed (by #4515)
1 parent 8798504 commit 3f55434

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Project: jackson-databind
66

77
2.18.0 (not yet released)
88

9+
#4119: Exception when deserialization uses a record with a constructor
10+
property with `access=READ_ONLY`
11+
(reported by @Mochis)
912
#4452: `@JsonProperty` not serializing field names properly
1013
on `@JsonCreator` in Record
1114
(reported by @Incara)

src/test/java/com/fasterxml/jackson/failing/CreatorWithReadOnlyParam4119Test.java renamed to src/test/java/com/fasterxml/jackson/databind/deser/creators/CreatorWithReadOnlyParam4119Test.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.databind.deser.creators;
22

33
import org.junit.jupiter.api.Test;
44

src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingCreatorImplicitNames2543Test.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
public class DelegatingCreatorImplicitNames2543Test
2121
extends DatabindTestUtil
2222
{
23-
static class Data {
23+
static class Data2543 {
2424

2525
final String part1;
2626
final String part2;
2727

2828
// this creator is considered a source of settable bean properties,
2929
// used during deserialization
3030
@JsonCreator(mode = PROPERTIES)
31-
public Data(@JsonProperty("part1") String part1,
31+
public Data2543(@JsonProperty("part1") String part1,
3232
@JsonProperty("part2") String part2) {
3333
this.part1 = part1;
3434
this.part2 = part2;
@@ -37,14 +37,15 @@ public Data(@JsonProperty("part1") String part1,
3737
// no properties should be collected from this creator,
3838
// even though it has an argument with an implicit name
3939
@JsonCreator(mode = DELEGATING)
40-
public static Data fromFullData(String fullData) {
40+
public static Data2543 fromFullData(String fullData) {
4141
String[] parts = fullData.split("\\s+", 2);
42-
return new Data(parts[0], parts[1]);
42+
return new Data2543(parts[0], parts[1]);
4343
}
4444
}
4545

4646
static class DelegatingCreatorNamedArgumentIntrospector
47-
extends JacksonAnnotationIntrospector {
47+
extends JacksonAnnotationIntrospector
48+
{
4849
private static final long serialVersionUID = 1L;
4950

5051
@Override
@@ -67,15 +68,15 @@ public String findImplicitPropertyName(AnnotatedMember member) {
6768

6869
@Test
6970
public void testDeserialization() throws Exception {
70-
Data data = MAPPER.readValue(a2q("{'part1':'a','part2':'b'}"), Data.class);
71+
Data2543 data = MAPPER.readValue(a2q("{'part1':'a','part2':'b'}"), Data2543.class);
7172

7273
assertThat(data.part1).isEqualTo("a");
7374
assertThat(data.part2).isEqualTo("b");
7475
}
7576

7677
@Test
7778
public void testDelegatingDeserialization() throws Exception {
78-
Data data = MAPPER.readValue(a2q("'a b'"), Data.class);
79+
Data2543 data = MAPPER.readValue(a2q("'a b'"), Data2543.class);
7980

8081
assertThat(data.part1).isEqualTo("a");
8182
assertThat(data.part2).isEqualTo("b");

src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingExternalProperty1003Test.java

+19-17
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,58 @@
55
import com.fasterxml.jackson.annotation.*;
66

77
import com.fasterxml.jackson.databind.*;
8+
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
89

910
import static org.junit.jupiter.api.Assertions.assertTrue;
1011

11-
public class DelegatingExternalProperty1003Test
12+
public class DelegatingExternalProperty1003Test extends DatabindTestUtil
1213
{
13-
static class HeroBattle {
14+
// [databind#1003]
15+
public interface Hero1003 { }
1416

15-
private final Hero hero;
17+
static class HeroBattle1003 {
1618

17-
HeroBattle(Hero hero) {
19+
private final Hero1003 hero;
20+
21+
HeroBattle1003(Hero1003 hero) {
1822
if (hero == null) throw new Error();
1923
this.hero = hero;
2024
}
2125

2226
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "heroType")
23-
public Hero getHero() {
27+
public Hero1003 getHero() {
2428
return hero;
2529
}
2630

2731
@JsonCreator
28-
static HeroBattle fromJson(Delegate json) {
29-
return new HeroBattle(json.hero);
32+
static HeroBattle1003 fromJson(Delegate1003 json) {
33+
return new HeroBattle1003(json.hero);
3034
}
3135
}
3236

33-
static class Delegate {
37+
static class Delegate1003 {
3438
@JsonProperty
3539
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "heroType")
36-
public Hero hero;
40+
public Hero1003 hero;
3741
}
3842

39-
public interface Hero { }
40-
41-
static class Superman implements Hero {
43+
static class Superman1003 implements Hero1003 {
4244
String name = "superman";
4345

4446
public String getName() {
4547
return name;
4648
}
4749
}
4850

51+
// [databind#1003]
4952
@Test
5053
public void testExtrnalPropertyDelegatingCreator() throws Exception
5154
{
52-
ObjectMapper mapper = new ObjectMapper();
53-
54-
final String json = mapper.writeValueAsString(new HeroBattle(new Superman()));
55+
ObjectMapper mapper = newJsonMapper();
5556

56-
final HeroBattle battle = mapper.readValue(json, HeroBattle.class);
57+
final String json = mapper.writeValueAsString(new HeroBattle1003(new Superman1003()));
58+
final HeroBattle1003 battle = mapper.readValue(json, HeroBattle1003.class);
5759

58-
assertTrue(battle.getHero() instanceof Superman);
60+
assertTrue(battle.getHero() instanceof Superman1003);
5961
}
6062
}

0 commit comments

Comments
 (0)