There is one set of definition as follows:
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
property = "type",
visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "dog"),
@JsonSubTypes.Type(value = Cat.class, name = "cat")})
public abstract class Animal implements Serializable{
AnimalType type;
}
public class Dog extends Animal { AnimalType type = new AnimalType("dog"); }
public class Cat extends Animal { AnimalType type = new AnimalType("cat"); }
There is another set of definition as follows:
public class Pets
{
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, defaultImpl = Dog.class)
Doggies doggies;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, defaultImpl = Cat.class)
Kitties kitties;
public static class Doggies extends ArrayList<Dog> {
}
public static class Kitties extends ArrayList<Cat>{
}
}
The actual data on the wire is as follows(*the important thing is it
does NOT have a "type" field but otherwise is json compatible with Dog/Cat
types*):
{
"doggies": [
]
"kitties": [
]
}
I tried to use RestTemplate to receive the data:
restTemplate.exchange(....Pets.class);
It worked! But the question is - is it working out of chance? or is it the
right approach to Jackson?
The reason I ask this question is - how does Jackson make use of
'defaultImpl'? It is working on an array at the time but somehow takes the
suggestion of "defaultImpl" to be used on the array element (rather than
the array itself)?
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.