Reputation: 1591
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: 1081
Reputation: 49814
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