I am very new to Jaxb and this maven-jaxb2 plugin
Here is my .xsd file :
<xs:element name="user" type="user" />
<xs:element name="userList" type="userList" />
<xs:complexType name="user">
<xs:all>
<xs:element name="id" type="xs:long" minOccurs="0" />
<xs:element name="name" type="xs:string" />
<xs:element name="registrationDate" type="xs:dateTime" />
</xs:all>
</xs:complexType>
<xs:complexType name="userList">
<xs:sequence>
<xs:element name="user" type="user" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
Here is my .xjb file :
<!-- Annotate @XmlRootElement Annotation for all the classes, that matches
in the .xsd with complexType -->
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType['1'='1']" multiple="true"
required="false">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
name="user" />
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
and when it generates it gives the java class somewhat like :
XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "user", propOrder = {
})
@Entity
@XmlRootElement(name = "${@name}")
@Table(schema = "schemaName", uniqueConstraints = {
}, name = "user_")
public class User
implements Serializable, ToString
{
private final static long serialVersionUID = 1L;
protected Long id;
where it should give name = object name such as here "user" I know if I write in bindings like this it will genearate
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType[@name='user']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="user" />
</annox:annotate>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[@name='userList']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="userList" />
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
but i dont want to repeat the same code for user and userlist is there any way I can do by annotations or defining regular expression. Please suggest some way.
I just wanted to know what to write in this code
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
name="user" />
</annox:annotate>
so that when it creates user class it show @xmlRootElement(name='user') and similary for other class @xmlRootElement(name='userList') ans similarly for others.