|
| 1 | +package com.fasterxml.jackson.failing; |
| 2 | + |
| 3 | +import java.util.*; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 6 | +import com.fasterxml.jackson.databind.BaseMapTest; |
| 7 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 8 | +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
| 9 | + |
| 10 | +// Tests for problems uncovered with [databind#2016]; related to |
| 11 | +// `@JsonDeserialize` modifications to type, deserializer(s) |
| 12 | +public class DelegatingCreatorAnnotations2016Test extends BaseMapTest |
| 13 | +{ |
| 14 | + // [databind#2016] |
| 15 | + static class Wrapper2016As { |
| 16 | + Object value; |
| 17 | + |
| 18 | + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) |
| 19 | + public Wrapper2016As(@JsonDeserialize(as = java.util.Date.class) Object v) { |
| 20 | + value = v; |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + static class Wrapper2016ContentAs { |
| 25 | + List<Object> value; |
| 26 | + |
| 27 | + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) |
| 28 | + public Wrapper2016ContentAs(@JsonDeserialize(contentAs = java.util.Date.class) List<Object> v) { |
| 29 | + value = v; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + /* |
| 34 | + /********************************************************************** |
| 35 | + /* Test methods |
| 36 | + /********************************************************************** |
| 37 | + */ |
| 38 | + |
| 39 | + private final ObjectMapper MAPPER = newObjectMapper(); |
| 40 | + |
| 41 | + // [databind#2016] |
| 42 | + public void testDelegatingWithAs() throws Exception |
| 43 | + { |
| 44 | + Wrapper2016As actual = MAPPER.readValue("123", Wrapper2016As.class); |
| 45 | + assertEquals(Date.class, actual.value.getClass()); |
| 46 | + } |
| 47 | + |
| 48 | + public void testDelegatingWithContentAs() throws Exception |
| 49 | + { |
| 50 | + Wrapper2016ContentAs actual = MAPPER.readValue("[123]", Wrapper2016ContentAs.class); |
| 51 | + List<Object> l = actual.value; |
| 52 | + assertEquals(1, l.size()); |
| 53 | + assertEquals(Date.class, l.get(0).getClass()); |
| 54 | + } |
| 55 | +} |
0 commit comments