The scenario is I have a bunch of schemas in .xsd format, which I can generate using XJC. However, I do not like one of the class generated using this approach, as a result, I would like to manually curate a replacement for that specific class. That class is being referenced by other classes in the schema. Is there a way of doing that?
-
1possible duplicate of [jaxb xjc mapping to existing domain objects](http://stackoverflow.com/questions/10420137/jaxb-xjc-mapping-to-existing-domain-objects) – bdoughan May 29 '13 at 18:43
3 Answers
You can use an external binding file to configure XJC to do what you want. In the example below the existing class com.example.Foo
will be used for the complex type named Foo
.
binding.xml
<jxb:bindings schemaLocation="yourSchema.xsd">
<jxb:bindings node="//xs:complexType[@name='Foo']">
<jxb:class ref="com.example.Foo"/>
</jxb:bindings>
</jxb:bindings>
XJC Call
xjc -d outputDir -b binding.xml yourSchema.xsd

- 147,609
- 23
- 300
- 400
You can manually create the class you have to use jaxb annotaion from javax.xml.bind.annotation package in you class.
below is the link for details of the same. http://docs.oracle.com/javaee/5/api/javax/xml/bind/annotation/package-summary.html
but if you can be more specific to your question like what you didnt like in autogenerated classes like class name or package name or anything else that will be a great help to answer this question.

- 411
- 4
- 7
As long as you are annotating the fields/properties with the same values, it is ok to manually change your class and also change any references(including the ObjectFactory class).

- 166
- 2
- 7