Issue
I am using NetBeans 8.2.
I have generated some java sources using JaxB and xsd schema that was provided to me.
(by the way the xsd
schema is given and should not change)
Now in order to be able to marshal objects into xml
properly (e.g to have a correct timestamp format) I had to add some annotations to the generated sources like the following
@XmlJavaTypeAdapter(DateTimeAdapter.class)
protected XMLGregorianCalendar timestamp;
Everything runs smoothly.
However, the problem is that on clean and build all the generated files are regenerated anew and added annotations are lost.
What can I do, so that either:
- clean and build will leave generated sources untouched
or
- needed annotations are automatically inserted into generated files after clean and build ?
Solution
So, the jaxb
binding in Netbeans
creates JaxBBindings
Directory, in which it puts the binding xsd
file.
What one needs to do is to edit this xsd
and add proper (inline) binding customisation.
Note that in order for the following to compile I had to check "Use Extension"
in "Change JAXB options"
menu (right click on bindings subfolder).
<xsd:schema ...
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc"
>
...
<xsd:element name="Timestamp" type="xsd:dateTime">
<xsd:annotation>
<xsd:appinfo>
<xjc:javaType name="javax.xml.datatype.XMLGregorianCalendar" adapter="myadapters.DateTimeAdapter"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
...
Answered By - PKey