0

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.

1 Answer 1

2

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.

4
  • 1
    Ravi, I don't want to change the JAXB class. Is it possible to do this programmatically when i unmarshall Commented Dec 24, 2017 at 13:57
  • @user2913809 what is the big deal of making above change ? why is it so important than your expected output ?
    – Ravi
    Commented Dec 24, 2017 at 17:00
  • The JAXB class resides in a third party jar. Creating a new JAXB class will lead to more changes in the existing code. Commented Dec 26, 2017 at 0:05
  • 1
    ok, then override this class for unwanted field use transient annotation
    – Ravi
    Commented Dec 26, 2017 at 4:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.