|
| 1 | +package com.fasterxml.jackson.failing; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.JsonIdentityInfo; |
| 6 | +import com.fasterxml.jackson.annotation.JsonSubTypes; |
| 7 | +import com.fasterxml.jackson.annotation.JsonTypeInfo; |
| 8 | +import com.fasterxml.jackson.annotation.ObjectIdGenerators; |
| 9 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 10 | + |
| 11 | +import org.junit.jupiter.api.Assertions; |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | + |
| 14 | +import static com.fasterxml.jackson.databind.BaseMapTest.newJsonMapper; |
| 15 | + |
| 16 | +public class TypeId4607Test { |
| 17 | + |
| 18 | + @JsonIdentityInfo(generator = ObjectIdGenerators.StringIdGenerator.class) |
| 19 | + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME) |
| 20 | + @JsonSubTypes({ |
| 21 | + @JsonSubTypes.Type(value = EnumTypeDefinition.class, name = "enum"), |
| 22 | + @JsonSubTypes.Type(value = NumberTypeDefinition.class, name = "number") |
| 23 | + }) |
| 24 | + interface TypeDefinition { |
| 25 | + } |
| 26 | + |
| 27 | + static class EnumTypeDefinition implements TypeDefinition { |
| 28 | + public List<String> values; |
| 29 | + } |
| 30 | + |
| 31 | + static class NumberTypeDefinition implements TypeDefinition { |
| 32 | + } |
| 33 | + |
| 34 | + private static final ObjectMapper mapper = newJsonMapper(); |
| 35 | + |
| 36 | + @Test |
| 37 | + public void shouldHandleTypeDefinitionJson() throws Exception { |
| 38 | + String input = "{" + |
| 39 | + " \"@type\": \"number\" " + |
| 40 | + " }"; |
| 41 | + |
| 42 | + TypeDefinition model = mapper.readValue(input, TypeDefinition.class); |
| 43 | + |
| 44 | + Assertions.assertInstanceOf(NumberTypeDefinition.class, model); |
| 45 | + } |
| 46 | +} |
| 47 | + |
0 commit comments