There are several different options:
Option number 1 - enter the field
If the value is constant, as it is in your example, you can enter a field in your domain class and map JAXB to this:
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; @XmlType(name = "foo") @XmlAccessorType(XmlAccessType.NONE) public final class Foo { @XmlElement private final String title = "hello, world!"; public String title() { return title; } }
Option number 2 - Enter the property
If the value is calculated, you will need to enter the JavaBean accessory and have the following JAXB card:
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; @XmlType(name = "foo") @XmlAccessorType(XmlAccessType.NONE) public final class Foo { public String title() { return "hello, world!"; } @XmlElement public String getTitle() { return title(); } }
source share