delita
delita

Reputation: 1581

XStream deserialize object through desired constructor

In xstream for java, is there a way to deserialize an object by ensuring that it goes thru a specific constructor with parameters?

Upvotes: 2

Views: 1080

Answers (1)

biziclop
biziclop

Reputation: 49754

XStream (or deserialization in general) doesn't call constructors. (Except in the rarely used Pure Java Mode, when it calls the default constructor.)

You need to use the readResolve() method if you want to initialise transient fields.

However you can write your own converter, and then you can do whatever you want. This approach works best if you have one specific class that you want to apply this to.

Upvotes: 3

Related Questions