-
-
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
1 parent
d1a8e71
commit 69334dd
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
.../java/com/fasterxml/jackson/databind/tofix/PolymorphicDeserWithJsonUnwrapped4792Test.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,59 @@ | ||
package com.fasterxml.jackson.databind.tofix; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; | ||
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
|
||
import static com.fasterxml.jackson.annotation.JsonProperty.Access.READ_ONLY; | ||
|
||
// [databind#4792] JsonUnwrapped throwing "Unrecognized field" after upgrade to 2.18 | ||
public class PolymorphicDeserWithJsonUnwrapped4792Test | ||
extends DatabindTestUtil | ||
{ | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "name") | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = SubA.class, name = "A"), | ||
}) | ||
interface Parent { } | ||
|
||
static class SubA implements Parent { | ||
@JsonUnwrapped | ||
@JsonProperty(access = READ_ONLY) | ||
private Model model; | ||
|
||
@JsonCreator | ||
public SubA(@JsonProperty("model") Model model) { | ||
this.model = model; | ||
} | ||
} | ||
|
||
static class Model { | ||
public String name; | ||
} | ||
|
||
public static class Wrapper { | ||
public Parent model; | ||
} | ||
|
||
private final ObjectMapper objectMapper = newJsonMapper(); | ||
|
||
@JacksonTestFailureExpected | ||
@Test | ||
public void testMainTest() | ||
throws Exception | ||
{ | ||
Wrapper w = objectMapper.readValue(a2q("{'model':{'name':'A','name': 'Rick'}}"), Wrapper.class); | ||
|
||
assertInstanceOf(SubA.class, w.model); | ||
assertInstanceOf(Model.class, ((SubA) w.model).model); | ||
assertEquals("Rick", ((SubA) w.model).model.name); | ||
} | ||
|
||
} |