【问题标题】:How to serialize non primitive data using JAXB?如何使用 JAXB 序列化非原始数据?
【发布时间】:2020-08-21 14:16:41
【问题描述】:

我想使用 JAXB 序列化一个对象。我的类定义如下所示:

@XmlRootElement
public class MyClass{
     <<How do I annotate this one?>>
     private xyz_type xyz;
     @XmlElement(name = "unique")
     private int unique;
} 
public class xyz_type extends abc_type{
    private qwe_tpe qwe;
    public static final ert_type ARRAY = ert_type.ARRAY; 
} 

提前感谢您的帮助!

【问题讨论】:

  • 问题是什么?怎么了?你期望什么,你得到什么?
  • 可以添加@XmlElement(name = "xyz", required = true)private xyz_type xyz;之类的注解
  • @GigaKokaia 我的 xml 文件中只列出了原始数据类型。
  • @SanthoshKThadka 我试过了,但它不起作用。
  • 字段有getter,需要序列化吗?

标签: java xml-parsing jaxb xml-serialization


【解决方案1】:

您需要一个客户 XML 适配器来编组复杂的数据类型。

请参阅本指南:https://www.baeldung.com/jaxb - 6. 复杂数据类型

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 2020-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多