Reputation: 818
I have a parent class which contains an enum "ActionType".
@XmlRootElement(name="Action")
public class ActionDto {
[...] ActionType type;
}
and some child-classes which extends ActionDto and have more special attributes like password (the LoginDto).
It's a server-client-connection. I want to send some data from my client to my server. So I serialize it (I use Jaxb) and deserialize it to an ActionDto-object.
An example for a LoginDto-Object:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Action>
<type>LOGIN</type>
<password>Testpassword</password>
</Action>
I get an error if I want to deserialize it to an ActionDto-object - I think it's caused by the password-attribute. Can I make the Jaxb-unmarshaller ignore those unknown attributes?
Is there an other possibility to unmarshal it directly to my LoginDto-Object (The server receives just a xml-String, I don't know the special type) ?
Upvotes: 2
Views: 8272
Reputation: 149047
By default a JAXB implementation will ignore unknown elements. If it is throwing an exception the default ValidationEventHandler
has been replaced on the Unmarshaller
. You will need to replace the one that with one that is less sensitive.
Upvotes: 4