2011-10-04 62 views
2

我正在使用JiBX进行XML-Java数据绑定。当前的配置生成的类很好,但我希望这些生成的类实现java.io.Serializable。使数据模型类可串行化

这里是maven插件配置从给定模式生成java类。

<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建议使用org.jibx.schema.codegen.extend.SerializableDecorator为了实现java.io.Serializable所有生成的类。但我不知道如何编写自定义文件并配置jibx-maven-plugin。

任何人都可以请指导我做到这一点?

回答

3

我能够得到它。

我创建了src/main/resources/schema-customizations.xml。这个自定义配置文件的内容是:

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

还修改的pom.xml在定制配置中添加下<configuration>

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

和运行mvn jibx:schema-codegen

现在所有生成的类实现java.io.Serializable

谢谢@SB

+0

您也可以选择将serial-version属性添加到class-decorator元素。它会像