I have something like this:
Java Class
.....
@XStreamAlias("SOME_TAG")
private String someAttribute;
.....
<ROOT>
<ANOTHER_TAG>VALUE</ANOTHER_TAG>
</ROOT>
And in my xml i need to have this "SOME_TAG", if for some reason it is missing i need to throw an exception.
Can i do it with XStream?
Regards
I'm not a experimented user of xstream, but I would do this:
Purely using XStream I think you have two options:
XStream uses the same mechanism as the JDK serialization, so you can simply implement a Object readResolve() method in your class that is being deserialized. This method is called after the object has been initialized and had all fields set by XStream, so you can use this method to check if your someAttribute field is null - if it is you can then throw an exception. (Examples from XStream can be found here: http://x-stream.github.io/faq.html#Serialization_initialize_transient
Another alternative would be to write a custom Converter for your class and check there if the field is filled or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With