-
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
daf3e37
commit 2610a95
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
src/test/java/com/fasterxml/jackson/databind/tofix/CreatorWithIgnoreProperties3355Test.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,84 @@ | ||
package com.fasterxml.jackson.databind.tofix; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
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.assertNotNull; | ||
|
||
// [databind#3355] Deserialization fails depending on the order of deserialized | ||
// objects with "Cannot construct instance (although at least one Creator exists)" | ||
public class CreatorWithIgnoreProperties3355Test | ||
extends DatabindTestUtil | ||
{ | ||
static class Common3355 { | ||
private final String property; | ||
private final ContainerFail3355 container; | ||
|
||
@JsonCreator | ||
public Common3355(@JsonProperty("property") final String property, | ||
@JsonProperty("container") final ContainerFail3355 container) { | ||
this.property = property; | ||
this.container = container; | ||
} | ||
|
||
public String getProperty() { | ||
return property; | ||
} | ||
|
||
public ContainerFail3355 getContainer() { | ||
return container; | ||
} | ||
} | ||
|
||
static class ContainerFail3355 { | ||
private final Common3355 common; | ||
|
||
@JsonCreator | ||
public ContainerFail3355(@JsonProperty("common") final Common3355 common) { | ||
this.common = common; | ||
} | ||
|
||
@JsonIgnoreProperties("container") | ||
public Common3355 getCommon() { | ||
return common; | ||
} | ||
} | ||
|
||
private final ObjectMapper MAPPER = newJsonMapper(); | ||
|
||
@JacksonTestFailureExpected | ||
@Test | ||
public void testDeserFailing() throws Exception | ||
{ | ||
final String objectJson = "{ \"property\": \"valueOne\" }"; | ||
final String containersJson = "{ \"common\": { \"property\": \"valueTwo\" } }"; | ||
|
||
// If we deserialize inner object first, outer object FAILS | ||
Common3355 object = MAPPER.readValue(objectJson, Common3355.class); | ||
ContainerFail3355 container = MAPPER.readValue(containersJson, ContainerFail3355.class); | ||
|
||
assertNotNull(object); | ||
assertNotNull(container); | ||
} | ||
|
||
@Test | ||
public void testDeserPassing() throws Exception | ||
{ | ||
final String objectJson = "{ \"property\": \"valueOne\" }"; | ||
final String containersJson = "{ \"common\": { \"property\": \"valueTwo\" } }"; | ||
|
||
// If we deserialize outer object first, it WORKS | ||
final ContainerFail3355 container = MAPPER.readValue(containersJson, ContainerFail3355.class); | ||
final Common3355 object = MAPPER.readValue(objectJson, Common3355.class); | ||
|
||
assertNotNull(object); | ||
assertNotNull(container); | ||
} | ||
} |