9

Having JAXB-RI and CXF. WSDL first. I want a generated class of mine to implement Serializable. I now have the following binding xml, which works (the SEI class name gets changed)

<jaxws:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...>
    <bindings node="wsdl:definitions/wsdl:portType[@name='Foo']">
        <!-- change the generated SEI class -->
        <class name="IFooService" />
    </bindings>
</jaxws:bindings>

No, in this context, where and what should I add. I tried:

<xsd:annotation>
    <xsd:appinfo>
        <jaxb:globalBindings>
            <xjc:serializable uid="12343" />
        </jaxb:globalBindings>
    </xsd:appinfo>
</xsd:annotation>

and

<jxb:globalBindings>
    <jxb:serializable/>
</jxb:globalBindings> 

both inside and outside the <bindings> tag - either Serializable is not added, or classes are not generated at all (without any error).

See also this thread

So, how exactly to do that

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • JAXB binding customizations are a real pain in the neck. They're a hangover from the bad old days of JAXB 1.x, and it was never properly re-engineered for 2.x. – skaffman Jan 25 '11 at 09:54
  • possible duplicate of [How to generate a Java class which implements Serializable interface from xsd using JAXB?](http://stackoverflow.com/questions/1513972/how-to-generate-a-java-class-which-implements-serializable-interface-from-xsd-usi) – jmj Jan 25 '11 at 09:56

2 Answers2

7

I made it work in two ways:

  1. Using a second binding file, which is JAXB-only, as the one Pascal showed in his answer

  2. By specifying another <bindings> tag that handles the whole namespace:

    <bindings
        node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://www.yoursite.com/services/mynamespace']">
        <jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
            xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <jxb:serializable />
        </jxb:globalBindings>
    </bindings>
    
Community
  • 1
  • 1
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • Can you expand on these? For #1 how do you pass the second file to `wsimport`? For #2 where in the `` does this go and is `jaxws` the default namespace in your example? – OrangeDog Jan 03 '17 at 15:48
1

You can implement an XJC plugin to do that:

public class SerializablePlugin extends Plugin
{

  @Override
  public boolean run(Outline outline, Options options, ErrorHandler errorHandler) throws SAXException
  {
   for (ClassOutline classOutline : outline.getClasses())
   {
    JDefinedClass definedClass = classOutline.implClass;
    definedClass._implements(codeModel.ref(Serializable.class));
   }
   return true;
  }

 ...
}

Then, you can add the plugin to the SchemaCompiler options:

WsimportOptions wsimportOptions = new WsimportOptions();
wsimportOptions.getSchemaCompiler().getOptions().activePlugins.add(new SerializablePlugin());
Denian
  • 737
  • 2
  • 8
  • 17