GSON library
到是否有一个选项(写入自定义序列化器/反序列化器除外)不是序列化/反序列化超出某个级别的扩展类。GSON不对序列化/反序列化扩展类
例如看到下面的用例
class FirstClass {
int firstVariable;
}
class SecondClass extends FirstClass {
int secondVariable;
}
class ThirdClass extends SecondClass {
int thirdVariable;
}
现在使用fromJson
和toJson
当我想唯一的序列化/反序列化前两类的层次 - ThirdClass
和SecondClass
。这意味着它会忽略整个FirstClass
(和firstVariable
),因为这已经在level 3
。
为什么编写自定义类型适配器有问题?你可以组成类型适配器,它可以消除大部分的维护痛苦。 –