Skip to main content
Last updated March 29, 2011 23:08, by elygre
Feedicon  

value-constructor

The value constructor plugin provides a new constructor to the generated beans, with all the properties of the bean as constructor parameters. This is useful when you need to ensure that you fully populate a jaxb bean, and don't miss out on any properties. (In addition, a default no-argument constructor is generated, to make sure that existing code compiles with no change).

Using standard jaxb setters, you would use this:

   USAddress address = new USAddress();
   address.setName( name );
   address.setStreet( street );
   address.setCity( city );
   address.setState( state );
   address.setZip( new BigDecimal( zip ) );


With the value construct plugin, you may also use this:

   USAddress address = new USAddress(
       name,
       street,
       city,
       state,
       new BigDezimal(zip)
   );


Usage

Sample ant build.xml:

 <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
    <classpath>
       <pathelement path="/path/to/jaxb-xjc.jar"/>
       <pathelement path="/path/to/jaxb-value-constructor.jar" />
    </classpath>
 </taskdef> 
 <xjc>
    <arg value="-Xvalue-constructor" />
     ...
 </xjc>

Getting the plugin

The plugin is available in the central Maven repository, under http://repo2.maven.org/maven2/org/jvnet/jaxb2_commons/jaxb2-value-constructor/.

 
 
Close
loading
Please Confirm
Close