You can map abc
and then mark cdf
as @XmlTransient
(to prevent it from being populated as part of the unmarshal
.
@XmlRootElement(name="message")
class Message{
public String abc;
@XmlTransient
public String cdf;
}
Then you can leverage an unmarshal event to populate the cdf
field after the unmarshalling is done. Below are links to 2 different approachs for doing this:
- http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/Unmarshaller.Listener.html
- http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/Unmarshaller.html#unmarshalEventCallback
Corrections to Your Demo Code
You need to include the Message
class when creatig the JAXBContext
:
JAXBContext jc = JAXBContext.newInstance(Message.class);
Also you need to make sure the name you specify in the @XmlRootElement
annotation matches the root element name in your XML document. Currently you have a mismatch the case used for these.