Hi Simon, I haven't done this before, but the alternative ToString plugin (http://confluence.highsource.org/display/J2B/ToString+plugin) has a "-XtoString-toStringStrategyClass" option where you can apparently make up whatever toString() format you desire. This blog entry: http://www.jroller.com/gmazza/entry/enhancing_jaxb_artifacts#Plugin can show you how to use the plugin itself, but creating the toString() strategy itself may require some googling of source code to find out the process.

HTH,
Glen


On 08/31/2012 06:09 AM, Simon wrote:
Hi !

I'am using CXF (2.6.1) for my projects and I would like to have a
toString() method for our generated JAXB classes.

I'am using Maven as the build system.

The easier solution seems to use the 'cxf-codegen-plugin' in
combination with the 'toString() XJC Plugin' like this :

<plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>2.6.1</version>
        <dependencies>
            <dependency>
                        <groupId>org.apache.cxf.xjcplugins</groupId>
                        <artifactId>cxf-xjc-ts</artifactId>
                        <version>2.6.0</version>
             </dependency>
        </dependencies>
        <configuration>
                <defaultOptions>
                        <extraargs>
                                
<extraarg>-xjc-Xts:style:org.apache.commons.lang.builder.ToStringStyle.SIMPLE_STYLE</extraarg>
                        </extraargs>
                </defaultOptions>
        </configuration>
        <executions>
                <execution>
                        <id>generate-sources</id>
                        <goals>
                                <goal>wsdl2java</goal>
                        </goals>
                </execution>
        </executions>
</plugin>

This will generate this :

@Override
public String toString() {
     return ToStringBuilder.reflectionToString(this, 
ToStringStyle.SIMPLE_STYLE);
}

However, as my projects are all using Guava, I would prefere to
generate the toString() method this way :

@Override
public String toString() {
     return Objects.toStringHelper(this)
        .add("name", name)
        .add("phone", phone)
        .add("eMail", eMail)
        .add("fax", fax)
        .toString();
}

Is there a plan to add this feature (using Guava) in the existing XJC Plugin ?

Thank you !


--
Glen Mazza
Talend Community Coders - coders.talend.com
blog: www.jroller.com/gmazza

Reply via email to