Search code examples
javajaxbjaxb2

Jaxb : Append field of Request XML without modfying JAXB java class


I am using JAXB 2.0 for the Application Deveopment which is using RestFul Webservices . Now there is a modification in the request , that is i will be getting another filed/variable in the request XML .

<Root Id="567" att="758" />   

Modified Request will be

 <Root Id="567" att="758" anotherfiledadded ="kiran" />   

My question is , is it possible to automatically append that field (anotherfiledadded)in the UserData class (Without modifying the UserData ??)

The below is my UserData class

@XmlRootElement(name = "Root")
@XmlAccessorType(XmlAccessType.FIELD)

public class UserData {

    @XmlAttribute
    private String Id;

    @XmlAttribute
    private String att;

// getters and setters 

Solution

  • You can try adding the field at runtime with javassist. But... It looks like you would also require to add the Annotation @XmlAttribute and I don't know if javassist allows you to add annotations... Anyways give it a try.

    See: Javassist Add