users@jaxb.java.net

Re: Making generated classes serializable

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Fri, 12 Jun 2009 07:48:41 +0200

Wrap the globalBindings element in a jaxb:bindings, specifying the schema
locatiion

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
             version="2.0">
  <jaxb:bindings schemaLocation="uri">
    <jaxb:globalBindings>
      <jaxb:serializable/>
    </jaxb:globalBindings>
  </jaxb:bindings>
 </jaxb:bindings>

This will give you "implements Serializable", but no serialVersionUID; you
can request this
by specifying attribute uid="<int>" but this value is used in all classes.

-W

On Thu, Jun 11, 2009 at 11:41 PM, Ryan O'Connell <Ryan.Oconnell_at_sun.com>wrote:

> Hello,
>
> In the past I was able to compile DTDs using JAXB. I also specified a
> custom binding that made each implementation class Serializable. The
> version of JAXB I was using created interfaces for all XML content as well
> as impls of those interfaces
>
> The binding file contained the following content:
>
> <?xml version="1.0" ?>
> <xml-java-binding-schema xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
> <xjc:serializable uid="1" />
> </xml-java-binding-schema>
>
> And I invoked the JAXB compiler using the xjc task like so:
>
> <xjc schema="${ts.home}/lib/dtds/sun-application_5_0-0.dtd"
> binding="${ts.home}/src/${porting.package.dir}/jaxb-cust.xml"
> target="${ts.home}/src"
> package="${porting.package}.app">
> <arg value="-dtd"/>
> <depends dir="${ts.home}/lib/dtds"
> includes="sun-application_6_0-0.dtd"/>
> <produces dir="${ts.home}/src/${porting.package.dir}/app"
> includes="**/*"/>
> </xjc>
>
>
> At some point I upgraded to JAXB 2.x and I noticed interfaces were no
> longer generated just plain Java classes, and I also noticed my classes did
> not implement Serializable. I have tried many variations of binding file
> and I can't seem to make it work. This binding file seems like it should
> work:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
> version="2.0">
> <jaxb:globalBindings>
> <jaxb:serializable/>
> </jaxb:globalBindings>
> </jaxb:bindings>
>
> but I keep getting the following error:
>
> [xjc] [ERROR] cvc-elt.1: Cannot find the declaration of element
> 'jaxb:globalBindings'.
> [xjc] line 3 of
> file:/Users/ryanoconnell/Documents/workspace/spider/src/com/sun/ts/lib/implementation/sun/javaee/runtime/jaxb-cust.xml
>
>
> Can anyone tell me where I fell off the beam?
>
> Thanks in advance.
> --ryano
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>