CrazySynthax
CrazySynthax

Reputation: 15018

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

Suppose I have the following 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 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. The difference is that class names differ and NewClass inherits fieldOne from BaseClass. In this case, will an error occur in deserialization by NewClass?

Upvotes: 0

Views: 27

Answers (1)

Léo Schneider
Léo Schneider

Reputation: 2305

If the fields are inherited or not doesn't matter to Jackson, it will check for the setters.

If it can deserialize, it will. You should encounter no issues to serialize OrigClass and deserialize NewClass

Upvotes: 1

Related Questions