Reputation: 1581
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
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