使数据模型类可序列化

发布于 2024-12-07 20:10:47 字数 1740 浏览 0 评论 0原文

我正在使用 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>

此链接建议使用org.jibx.schema.codegen.extend .SerializedDecorator 以便为所有生成的类实现 java.io.Serializable。但我不知道如何编写自定义文件和配置 jibx-maven-plugin。

谁能指导我实现这一目标?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南街女流氓 2024-12-14 20:10:47

我能够得到它。

我创建了 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 以在 下添加自定义配置

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

并运行 mvn jibx:schema-codegen

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

谢谢@SB

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文