|
| 1 | +package com.fasterxml.jackson.failing; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 6 | + |
| 7 | +import com.fasterxml.jackson.core.JsonParser; |
| 8 | + |
| 9 | +import com.fasterxml.jackson.databind.BaseMapTest; |
| 10 | +import com.fasterxml.jackson.databind.DeserializationContext; |
| 11 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 12 | +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
| 13 | +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; |
| 14 | + |
| 15 | +// Tests for problems uncovered with [databind#2016]; related to |
| 16 | +// `@JsonDeserialize` modifications to type, deserializer(s) |
| 17 | +@SuppressWarnings("serial") |
| 18 | +public class DelegatingCreatorAnnotations2021Test extends BaseMapTest |
| 19 | +{ |
| 20 | + // [databind#2021] |
| 21 | + static class DelegatingWithCustomDeser2021 { |
| 22 | + public final static Double DEFAULT = 0.25; |
| 23 | + |
| 24 | + Number value; |
| 25 | + |
| 26 | + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) |
| 27 | + public DelegatingWithCustomDeser2021(@JsonDeserialize(using = ValueDeser2021.class) Number v) { |
| 28 | + value = v; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + static class ValueDeser2021 extends StdDeserializer<Number> { |
| 33 | + public ValueDeser2021() { super(Number.class); } |
| 34 | + |
| 35 | + @Override |
| 36 | + public Number deserialize(JsonParser p, DeserializationContext ctxt) |
| 37 | + throws IOException |
| 38 | + { |
| 39 | + p.skipChildren(); |
| 40 | + return DelegatingWithCustomDeser2021.DEFAULT; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + /* |
| 45 | + /********************************************************************** |
| 46 | + /* Test methods |
| 47 | + /********************************************************************** |
| 48 | + */ |
| 49 | + |
| 50 | + private final ObjectMapper MAPPER = newObjectMapper(); |
| 51 | + |
| 52 | + // [databind#2021] |
| 53 | + public void testCustomDeserForDelegating() throws Exception |
| 54 | + { |
| 55 | + DelegatingWithCustomDeser2021 actual = MAPPER.readValue(" true ", DelegatingWithCustomDeser2021.class); |
| 56 | + assertEquals(DelegatingWithCustomDeser2021.DEFAULT, actual.value); |
| 57 | + } |
| 58 | +} |
0 commit comments