Skip to content

Commit

Permalink
Merge branch '2.18'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 21, 2024
2 parents a49ab2d + 60140e6 commit 8f88bd4
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package tools.jackson.databind.tofix;

import com.fasterxml.jackson.annotation.JsonUnwrapped;

import org.junit.jupiter.api.Test;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.testutil.DatabindTestUtil;
import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected;

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

// [databind#4697] Inconsistent Serialization with Jackson’s @JsonUnwrapped Annotation
// Using Shared vs. New ObjectMapper Instances #4697
public class JsonUnwrappedInconsistentSerialization4697Test
extends DatabindTestUtil
{
public static class First {
@JsonUnwrapped(prefix = "")
public Third thrid = new Third();
}

public static class Second {
@JsonUnwrapped(prefix = "fromSecond")
public Third thrid = new Third();
}

public static class Third {
@JsonUnwrapped(prefix = "fromThird")
public Common common = new Common();

public Third() {
this.common.a = "a";
this.common.b = "b";
}
}

public static class Common {
public String a;
public String b;
public Common() {}
}

@JacksonTestFailureExpected
@Test
public void testInconsistentSer() throws Exception {
First first = new First();
Second second = new Second();

ObjectMapper firstMapper = newJsonMapper();
ObjectMapper secondMapper = newJsonMapper();

firstMapper.writeValueAsString(first);
assertEquals(
firstMapper.writeValueAsString(second),
secondMapper.writeValueAsString(second));
}
}

0 comments on commit 8f88bd4

Please sign in to comment.