-
-
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
5 changed files
with
120 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
88 changes: 88 additions & 0 deletions
88
src/test/java/com/fasterxml/jackson/databind/deser/Issue3913DeserTest.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,88 @@ | ||
package com.fasterxml.jackson.databind.deser; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.BaseMapTest; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.util.List; | ||
|
||
public class Issue3913DeserTest extends BaseMapTest | ||
{ | ||
// [databind#3913] | ||
static class MyResponse { | ||
List<Base> list; | ||
|
||
public List<Base> getList() { | ||
return list; | ||
} | ||
|
||
public void setList(List<Base> list) { | ||
this.list = list; | ||
} | ||
} | ||
|
||
interface Base { | ||
|
||
String getType(); | ||
|
||
String getMissingInJson(); | ||
|
||
@JsonCreator | ||
static Base unmarshall( | ||
@JsonProperty("missingInJson") String missingInJson, | ||
@JsonProperty("type") String type | ||
) { | ||
switch (type) { | ||
case "impl": | ||
return new Impl(type, missingInJson); | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
final static class Impl implements Base { | ||
private String type; | ||
private String missingInJson; | ||
|
||
public Impl() { | ||
} | ||
|
||
public Impl(String type, String missingInJson) { | ||
this.type = type; | ||
this.missingInJson = missingInJson; | ||
} | ||
|
||
@Override public String getType() { | ||
return type; | ||
} | ||
|
||
@Override public String getMissingInJson() { | ||
return missingInJson; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public void setMissingInJson(String missingInJson) { | ||
this.missingInJson = missingInJson; | ||
} | ||
} | ||
|
||
// [databind#3913] | ||
public void testDeserialization() throws JsonProcessingException { | ||
ObjectMapper mapper = jsonMapperBuilder() | ||
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||
.build(); | ||
String rawResponse = "{\"list\":[{\"type\":\"impl\",\"unmappedKey\":\"unusedValue\"}]}"; | ||
MyResponse myResponse = mapper.readValue(rawResponse, MyResponse.class); | ||
assertNotNull(myResponse); | ||
assertEquals(1, myResponse.list.size()); | ||
assertEquals("impl", myResponse.list.get(0).getType()); | ||
assertNull(myResponse.list.get(0).getMissingInJson()); | ||
} | ||
} |