I am building an application for payara-micro. I need to convert a Json string to an object that extends a super class. The problem that I have is that both the parent and the child's fields are not populated and the instance created is not of type sub-class:
E.g. Person
has a list of Vehicle
(subtypes: Bike
, Bus
,...)
{
name: "John",
vehicles: [
{
type: "bike",
doors: 5
}
]
}
The resulting object of this json will be a Person
object with name
populated, and a list of Vehicle
with one element but the type of that element will be Vehicle
and no fields in Vehicle
will have a value.
Jsonb jsonb = JsonbBuilder.create();
Person person = jsonb.fromJson(jsonString, Person.class);