-
Notifications
You must be signed in to change notification settings - Fork 0
Inheritance
Inheritance of POJOs is supported out of the box. Suppose you have the following class hirarchy: abstract class Animal { String name; int legs; double intelligence; }
abstract class Mammal extends Animal
{
Gender gender;
}
public class Cat extends Mammal
{
public interface CatJsonReader extends JsonReader<Cat> {}
public static final CatJsonReader JSON = GWT.create(CatJsonReader.class);
String color;
}
and the following JSON data { "name": "Snowball", "legs": 4, "intelligence": 0.4, "gender": "female", "color": "dark grey" }
You can read Snowball using String json = ...; Cat snowball = Cat.JSON.read(json);
When (de)serializing POJOs Piriti automatically walks up the class hirarchy (upto but not including java.lang.Object). You can change that by using the @!MapUpTo annotation:
@MapUpTo(Mammal.class)
public class Cat extends Mammal
{
public interface CatJsonReader extends JsonReader {}
public static final CatJsonReader JSON = GWT.create(CatJsonReader.class);
String color;
}
In this setup the fields
- name
- legs and
- intelligence won't be processed.