Skip to content

Commit

Permalink
Mark #4119 as fixed (by #4515)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 30, 2024
1 parent 8798504 commit 3f55434
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Project: jackson-databind

2.18.0 (not yet released)

#4119: Exception when deserialization uses a record with a constructor
property with `access=READ_ONLY`
(reported by @Mochis)
#4452: `@JsonProperty` not serializing field names properly
on `@JsonCreator` in Record
(reported by @Incara)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.failing;
package com.fasterxml.jackson.databind.deser.creators;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
public class DelegatingCreatorImplicitNames2543Test
extends DatabindTestUtil
{
static class Data {
static class Data2543 {

final String part1;
final String part2;

// this creator is considered a source of settable bean properties,
// used during deserialization
@JsonCreator(mode = PROPERTIES)
public Data(@JsonProperty("part1") String part1,
public Data2543(@JsonProperty("part1") String part1,
@JsonProperty("part2") String part2) {
this.part1 = part1;
this.part2 = part2;
Expand All @@ -37,14 +37,15 @@ public Data(@JsonProperty("part1") String part1,
// no properties should be collected from this creator,
// even though it has an argument with an implicit name
@JsonCreator(mode = DELEGATING)
public static Data fromFullData(String fullData) {
public static Data2543 fromFullData(String fullData) {
String[] parts = fullData.split("\\s+", 2);
return new Data(parts[0], parts[1]);
return new Data2543(parts[0], parts[1]);
}
}

static class DelegatingCreatorNamedArgumentIntrospector
extends JacksonAnnotationIntrospector {
extends JacksonAnnotationIntrospector
{
private static final long serialVersionUID = 1L;

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

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

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

@Test
public void testDelegatingDeserialization() throws Exception {
Data data = MAPPER.readValue(a2q("'a b'"), Data.class);
Data2543 data = MAPPER.readValue(a2q("'a b'"), Data2543.class);

assertThat(data.part1).isEqualTo("a");
assertThat(data.part2).isEqualTo("b");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,58 @@
import com.fasterxml.jackson.annotation.*;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;

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

public class DelegatingExternalProperty1003Test
public class DelegatingExternalProperty1003Test extends DatabindTestUtil
{
static class HeroBattle {
// [databind#1003]
public interface Hero1003 { }

private final Hero hero;
static class HeroBattle1003 {

HeroBattle(Hero hero) {
private final Hero1003 hero;

HeroBattle1003(Hero1003 hero) {
if (hero == null) throw new Error();
this.hero = hero;
}

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "heroType")
public Hero getHero() {
public Hero1003 getHero() {
return hero;
}

@JsonCreator
static HeroBattle fromJson(Delegate json) {
return new HeroBattle(json.hero);
static HeroBattle1003 fromJson(Delegate1003 json) {
return new HeroBattle1003(json.hero);
}
}

static class Delegate {
static class Delegate1003 {
@JsonProperty
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "heroType")
public Hero hero;
public Hero1003 hero;
}

public interface Hero { }

static class Superman implements Hero {
static class Superman1003 implements Hero1003 {
String name = "superman";

public String getName() {
return name;
}
}

// [databind#1003]
@Test
public void testExtrnalPropertyDelegatingCreator() throws Exception
{
ObjectMapper mapper = new ObjectMapper();

final String json = mapper.writeValueAsString(new HeroBattle(new Superman()));
ObjectMapper mapper = newJsonMapper();

final HeroBattle battle = mapper.readValue(json, HeroBattle.class);
final String json = mapper.writeValueAsString(new HeroBattle1003(new Superman1003()));
final HeroBattle1003 battle = mapper.readValue(json, HeroBattle1003.class);

assertTrue(battle.getHero() instanceof Superman);
assertTrue(battle.getHero() instanceof Superman1003);
}
}

0 comments on commit 3f55434

Please sign in to comment.