Say I have a java class that is a representation of a “Dog” with attrbutes “Color” and “Type” marked up with @XmlElement and @XmlRootElement tags. How do I add a “Age” xml element to this JAXRS based class programmatically without modifying my Dog class with @XmlAttribute(name="Age")?
Assume I have the representation:
DogRepClass adog = new DogRepClass();
You can define your own MessageBodyWriter (http://jsr311.java.net/nonav/javadoc/javax/ws/rs/ext/MessageBodyWriter.html) only for this particular type. It can marshall your instance into DOM, modify it and serialize afterwards. Not nice nor elegant, but it will work.