2

I am using JiBX for XML-Java data binding. The current configuration generates classes pretty well but I want these generated classes to implement java.io.Serializable.

Here is maven plugin configuration to generate java classes from given schema.

<plugin>
    <groupId>org.jibx</groupId>
    <artifactId>jibx-maven-plugin</artifactId>
    <version>1.2.3</version>
    <configuration>
        <schemaLocation>src/main/resources</schemaLocation>            
        <includeSchemas>
            <includeSchema>FS_OTA_VehResRS.xsd</includeSchema>
        </includeSchemas>
        <options>
            <package>com.test.cars.model.ota2009a.vehresrs</package>
        </options>
        <schemaBindingDirectory>src/main/java</schemaBindingDirectory>
        <includeSchemaBindings>
            <includeSchemaBinding>*_binding.xml</includeSchemaBinding>
        </includeSchemaBindings>
    </configuration>
    <executions>            
        <execution>
        <id>generate-java-code-from-schema</id>
        <goals>
            <goal>schema-codegen</goal>
        </goals>
        </execution>
        <execution>
        <id>compile-the-binding-</id>
        <goals>
            <goal>bind</goal>
        </goals>
        </execution>            
    </executions>
</plugin>

This link suggesting to use org.jibx.schema.codegen.extend.SerializableDecorator in order implement java.io.Serializable to all generated classes. But I don't have idea how to write customization file and configure jibx-maven-plugin.

Can anyone please guide me to achieve this?

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
Amit Patel
  • 15,609
  • 18
  • 68
  • 106

1 Answers1

3

I am able to get it.

I created src/main/resources/schema-customizations.xml. The content of this custom config file is:

<schema-set xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <class-decorator class="org.jibx.schema.codegen.extend.SerializableDecorator"/>
</schema-set>

Also modified pom.xml to add in customization configuration under <configuration>

<customizations>
    <customization>src/main/resources/schema-customizations.xml</customization>
</customizations>

and run mvn jibx:schema-codegen

Now all generated classes are implementing java.io.Serializable

Thanks @SB

Amit Patel
  • 15,609
  • 18
  • 68
  • 106
  • You can also choose to add the serial-version attribute to the class-decorator element. It would be like – SB. Oct 04 '11 at 13:30