Код: Выделить всё
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "@type")
@JsonSubTypes({ @JsonSubTypes.Type(value = Dog.class, name = "dog") })
interface Animal {
String name = null;
}
@JsonTypeName("dog")
class Dog implements Animal {
public double barkVolume;
public String name;
}
class Zoo {
public Animal animal;
public Dog thisIsDog;
}
Код: Выделить всё
{
"animal": {
"@type": "dog",
"barkVolume": 12.0,
"name": "my dog;"
},
"thisIsDog": {
"barkVolume": 12.0,
"name": "my dog;"
}
}
< /code>
следующим образом: < /p>
Zoo newObject = new ObjectMapper().readValue(jsonString, Zoo.class);
< /code>
Но я получаю эту ошибку: < /p>
Missing type id when trying to resolve subtype of [simple type, class com.test.Dog]:
missing type id property '@type' (for POJO property 'thisIsDog')
Подробнее здесь: https://stackoverflow.com/questions/667 ... zation-wit
Мобильная версия