user2913809
user2913809

Reputation: 335

JAXB - Ignore an XML element

I have an XML

<SubTask id="3">
            <state>enabled</state>
       </SubTask

There is a JAXB class with two variable "id" and "state".Now when I unmarshall the above XML, I don't want to load the "id" element into the Java object. How can I do this programmatically? I don't want to change the Java class.

Upvotes: 0

Views: 3996

Answers (1)

Ravi
Ravi

Reputation: 31437

Assuming your JAXB class has

   @XmlElement(name="state")
   String state;

then you should use @XmlTransient to skip deserializing of element.

   @XmlTransient(name="state")
   String state;

Other possible solution is, remove those field from the class.

Upvotes: 2

Related Questions