Reputation: 3631
I'm using JAXB on a JDK 5 based app.
The XML marshaling is a side feature, so the annotations on the POJO model are excluded. The fields that should be excluded are transient
(the java keyword).
Is there a way to configure the Marshaler
to ignore those fields.
Here's the code I use to serialize my POJOs to XML:
JAXBContext context = JAXBContext.newInstance(BasePOJO.class, target.getClass());
JAXBElement<WsResponse> model = new JAXBElement<BasePOJO>(
new QName(target.getClass().getSimpleName()),
(Class<BasePOJO>) target.getClass(),
(BasePOJO)target
);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(model, os);
A sample POJO I need to serialize:
public class APOJO extends BasePOJO {
private Long id;
private String desc;
private transient String aFieldToIgnore;
//and the accessors[...]
}
Upvotes: 2
Views: 4629
Reputation: 1571
I don't believe there is a way to do this without using the @XmlTransient
annotation on your fields.
The only real customisations you can do are using binding files or in-line bindings in your XSD.
Check the reference for what is possible: http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.5/tutorial/doc/JAXBUsing4.html
Upvotes: 1