Hi guys,
I am receiving some simple XML messages from a device. Here two examples:
[XML]
<Response Action="Initialize" Result="1" Lane=”1” />
[/XML]
and
[XML]
<Response Action="CancelTransaction" Result="0" />
[/XML]
Well, now I have to unmarshall these messages to two different Java objects. I am using JAXB's for this annotations:
and
The problem now is that the unmarshaller does not recognize that the two XML messages are different object. Of course not because they have the same XML tag. The unmarshaller used the Java type that is defined last when creating the JAXBContext instance.
It there a possibility to decide with the "Action" attribute which Java object the unmarshaller has to create? ???:L
I am receiving some simple XML messages from a device. Here two examples:
[XML]
<Response Action="Initialize" Result="1" Lane=”1” />
[/XML]
and
[XML]
<Response Action="CancelTransaction" Result="0" />
[/XML]
Well, now I have to unmarshall these messages to two different Java objects. I am using JAXB's for this annotations:
Java:
@XmlRootElement(name = "Response")
public class InitializeResponseMessage {
@XmlAttribute(name = "Action")
private Integer action;
@XmlAttribute(name = "Result")
private Integer result;
@XmlAttribute(name = "Lane")
private Integer lane;
public InitializeResponseMessage() {}
}
Java:
@XmlRootElement(name = "Response")
public class CancelTransactionResponseMessage {
@XmlAttribute(name = "Action")
private Integer action;
@XmlAttribute(name = "Result")
private Integer result;
public InitializeResponseMessage() {}
}
The problem now is that the unmarshaller does not recognize that the two XML messages are different object. Of course not because they have the same XML tag. The unmarshaller used the Java type that is defined last when creating the JAXBContext instance.
It there a possibility to decide with the "Action" attribute which Java object the unmarshaller has to create? ???:L