Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB @XmlSeeAlso causing tight coupling to domain objects

I'm using JAXB bindings to unmarshal directly to my domain layer objects, which are subclasses of the generated webservice types. This is a nice solution as I can override methods and provide write custom logic, etc. However, the XJC compiler is insisting on putting the @XmlSeeAlso({MySubclass.class}) annotations on all the generated classes, which is causing them to be tightly coupled to my domain objects. This is obviously undesirable and causing all kinds of reference issues between my projects that I won't get into here.

Is it possible to generate classes that don't have the @XmlSeeAlso annotation? The actual work of unmarshaling to the subclass seems to happen in the ObjectFactory class. Is it possible to omit the jaxb binding, and substitute a custom ObjectFactory for each application? This would allow me to have autogenerated webservice types in a shared util while each web project could unmarshal to different subclasses of these types.

<jaxb:bindings node="//xs:complexType[@name='AutogeneratedWebserviceType']">
  <jaxb:class implClass="my.project.CustomSubclass" />
</jaxb:bindings>

This binding will create a method in the ObjectFactory that seems to do the actual work of unmarshaling to my subclass:

public AutogeneratedWebserviceType createAutogeneratedWebserviceType() {
  return new CustomSubclass();
}

I want this behavior without the @XmlSeeAlso annotation by providing a customer ObjectFactory, if possible.

like image 478
user1234057 Avatar asked May 05 '12 02:05

user1234057


1 Answers

Did you try running XJC with the argument -target 2.0? I believe this will disable the generation of the @XmlSeeAlso annotation.

like image 177
JamesB Avatar answered Oct 21 '22 17:10

JamesB