Serialization Deserialization parent subclass error
wudiffs opened this issue · 3 comments
wudiffs commented
`@Data
public class Item {
private String name;
private String type;
private String id;
}
@DaTa
public class Suit extends Item {
private String suitId;
}
@DaTa
public class Group {
private List<Item> itemList;
}`
protostuff Serialization Group,then Deserialization. lose Suit.suitId.
please check and help.
dyu commented
Easiest solution:
public abstract class Item {
If you can't make it abstract, then:
-Dprotostuff.runtime.morph_non_final_pojos=true
or
static final DefaultIdStrategy STRATEGY = new DefaultIdStrategy(IdStrategy.DEFAULT_FLAGS
| IdStrategy.MORPH_NON_FINAL_POJOS);
Schema<Group> schema = RuntimeSchema.getSchema(Group.class, STRATEGY);
wudiffs commented
Easiest solution:
public abstract class Item {If you can't make it abstract, then:
-Dprotostuff.runtime.morph_non_final_pojos=true
or
static final DefaultIdStrategy STRATEGY = new DefaultIdStrategy(IdStrategy.DEFAULT_FLAGS | IdStrategy.MORPH_NON_FINAL_POJOS); Schema<Group> schema = RuntimeSchema.getSchema(Group.class, STRATEGY);
why not open default? Performance loss?
leowangxf commented
another simple trick is to declare with super wildcard:
public class Group {
private List<? super Item> itemList;
}
but it's a bit annoyed you need explicitly cast the element like this:
Item item = (Item) group.itemList.get(0);
hope helpful