|
| 1 | +package com.fasterxml.jackson.failing; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.*; |
| 6 | + |
| 7 | +import com.fasterxml.jackson.core.*; |
| 8 | + |
| 9 | +import com.fasterxml.jackson.databind.*; |
| 10 | +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; |
| 11 | +import com.fasterxml.jackson.databind.module.SimpleModule; |
| 12 | + |
| 13 | +public class PolymorphicWithCustomDeser1300Test extends BaseMapTest |
| 14 | +{ |
| 15 | + // [databind#1300] |
| 16 | + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, |
| 17 | + include = JsonTypeInfo.As.PROPERTY, property = "type") |
| 18 | + @JsonSubTypes({ |
| 19 | + @JsonSubTypes.Type(value = T1.class, name = "T1") |
| 20 | + }) |
| 21 | + interface Type1300 {} |
| 22 | + |
| 23 | + @JsonTypeName("T1") |
| 24 | + static class T1 implements Type1300 { |
| 25 | + public int v; |
| 26 | + } |
| 27 | + |
| 28 | + /* |
| 29 | + /********************************************************** |
| 30 | + /* Test methods |
| 31 | + /********************************************************** |
| 32 | + */ |
| 33 | + |
| 34 | + // [databind#1300] |
| 35 | + @SuppressWarnings("serial") |
| 36 | + public void testDeserForPolymorphicBaseType() throws Exception |
| 37 | + { |
| 38 | + ObjectMapper mapper = new ObjectMapper(); |
| 39 | + SimpleModule mod = new SimpleModule("test", Version.unknownVersion()); |
| 40 | + mod.addDeserializer(Type1300.class, |
| 41 | + new StdDeserializer<Type1300>(Type1300.class) { |
| 42 | + @Override |
| 43 | + public Type1300 deserialize(JsonParser p, |
| 44 | + DeserializationContext ctxt) throws IOException |
| 45 | + { |
| 46 | + T1 result = new T1(); |
| 47 | + JsonNode n = ctxt.readValue(p, JsonNode.class); |
| 48 | + result.v = n.path("value").asInt(); |
| 49 | + return result; |
| 50 | + } |
| 51 | + }); |
| 52 | + Type1300 result = mapper.readValue("{\"value\":3, \"type\":\"bogus\"}", Type1300.class); |
| 53 | + assertEquals(T1.class, result.getClass()); |
| 54 | + assertEquals(3, ((T1) result).v); |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments