How to Prevent Serialization of Properties or Fields
By default, JAXB will serialize all public fields and properties of a bean. However, you can control this behaviour using the @XmlAccessorType annotation at class or package level. Instead of the default XmlAccessType.PUBLIC you can specify that only properties (XmlAccessType.PROPERTY), fields (XmlAccessType.FIELD) or no members (XmlAccessType.NONE) are serialized without a explicit annotation. Then only @XmlElement-annotated members will be written:
@XmlAccessorType(XmlAccessType.NONE)
public class Movie {
@XmlElement
public String title;
@XmlElement
public int releaseYear;
public String notWritten; // will not be serialized
}
The serialization of specific members can also be prevented with the @XmlTransient annotation, or (for fields) with the transient modifier:
public class Movie {
public String title;
public int releaseYear;
@XmlTransient
public String notWritten1; // will not be serialized
public transient String notWritten2; // will not be serialized
}

