I know the basics of the JAXB API, but I am stuck with something I am trying to do, and I am not sure whether it is actually possible. Details are as follows:
I have
JAXB will need either: - A public instance variable Or - A private instance variable with public mutators and accessors.
You will need mutators for marshalling and acessors for unmarshalling
You should keep your fields private in any case. You have 2 options binding to fields
1) annotate your fields with XmlElement or XmlAttribute annotation
@XmlRootElement(name="book")
public class Book {
@XmlElement
private String title;
...
2) annotate your class with @XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="book")
@XmlAccessorType(XmlAccessType.FIELD)
public class Book {
private String title;
...