简体   繁体   English

Jackson:当 class 名称更改并且 class 从另一个 ZA2F2ED4F8EBC2CBB64C21A29DC4 继承时,序列化是否应该更改?

[英]Jackson: should serialization change when class name changes and class inherits from another class?

Suppose I have the following class:假设我有以下 class:

class OrigClass {
    private int fieldOne;
    private int field Two;
    // getters and setters
}

Let's say that I serialize an object of this class, and pass it read it by the class NewClass:假设我序列化了这个 class 的 object,并通过 class NewClass 读取它:

class NewClass extends BaseClass {
    private int fieldOne;
    // getters and setters
}

class BaseClass {
    private int field Two;
    // getters and setters
}

As you can see, an object of NewClass has exactly the same properties as the properties of OrigClass.如您所见,NewClass 的 object 具有与 OrigClass 的属性完全相同的属性。 The difference is that class names differ and NewClass inherits fieldOne from BaseClass.不同之处在于 class 名称不同,NewClass 从 BaseClass 继承 fieldOne。 In this case, will an error occur in deserialization by NewClass?这种情况下,NewClass反序列化会不会出错?

If the fields are inherited or not doesn't matter to Jackson, it will check for the setters.如果字段是否被继承与 Jackson 无关,它将检查设置器。

If it can deserialize, it will.如果它可以反序列化,它会。 You should encounter no issues to serialize OrigClass and deserialize NewClass序列化OrigClass和反序列化NewClass应该没有问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM