-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...est/java/tools/jackson/databind/tofix/JsonUnwrappedInconsistentSerialization4697Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |