|
| 1 | +package com.fasterxml.jackson.databind.jsontype.ext; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.*; |
| 6 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 7 | +import com.fasterxml.jackson.databind.*; |
| 8 | + |
| 9 | +public class ExternalTypeIdWithIgnoreUnknownTest extends BaseMapTest |
| 10 | +{ |
| 11 | + // [databind#2611] |
| 12 | + @JsonIgnoreProperties(ignoreUnknown = true) |
| 13 | + static class Wrapper2611 { |
| 14 | + private String type; |
| 15 | + |
| 16 | + @JsonTypeInfo( |
| 17 | + use = JsonTypeInfo.Id.NAME, |
| 18 | + include = JsonTypeInfo.As.EXTERNAL_PROPERTY, |
| 19 | + property = "type", |
| 20 | + defaultImpl = Default2611.class |
| 21 | + ) |
| 22 | + private Default2611 data; |
| 23 | + |
| 24 | + @JsonCreator |
| 25 | + public Wrapper2611( |
| 26 | + @JsonProperty(value = "type", required = true) String type, |
| 27 | + @JsonProperty(value = "data", required = true) Default2611 data |
| 28 | + ) { |
| 29 | + this.type = type; |
| 30 | + this.data = data; |
| 31 | + } |
| 32 | + |
| 33 | + String getType() { |
| 34 | + return type; |
| 35 | + } |
| 36 | + |
| 37 | + Default2611 getData() { |
| 38 | + return data; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + static class Default2611 {} |
| 43 | + |
| 44 | + private final ObjectMapper MAPPER = newJsonMapper(); |
| 45 | + |
| 46 | + // [databind#2611] |
| 47 | + public void testDeserialization() throws Exception |
| 48 | + { |
| 49 | + final String data = aposToQuotes("[{'type': 'test','data': {},'additional': {}}]"); |
| 50 | + |
| 51 | + List<Wrapper2611> result = MAPPER.readValue(data, new TypeReference<List<Wrapper2611>>() {}); |
| 52 | + |
| 53 | + assertEquals(1, result.size()); |
| 54 | + |
| 55 | + Wrapper2611 item = result.get(0); |
| 56 | + assertEquals("test", item.getType()); |
| 57 | + assertNotNull(item.getData()); |
| 58 | + } |
| 59 | +} |
0 commit comments