我正在使用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。
有人可以指导我实现这个目标吗?
答案 0 :(得分: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