简体   繁体   English

可以使用jaxb在此xml中进行继承吗?

[英]Is possible to make inheritance in this xml using jaxb?

I want to know if is possible to create a abstract class adress to using with job and home tags? 我想知道是否可以创建一个与jobhome标签一起使用的抽象类adress

Like in this code 就像这段代码

<person>
  <home>
    <adress>
      <street>marte</street>
      <number>200</number>
    </adress>
  </home>
  <job>
    <adress>
      <street>saint loius</street>
      <number>100</number>
    </adress>
  </job>
</person>

If is possible, can someome show me a example code... 如果可能,有人可以给我看一个示例代码...

This can be done by leveraging the @XmlElementRef annotation on a property in which the type is the common super class. 这可以通过在类型为公共超类的属性上利用@XmlElementRef注释来完成。 Then annotate each subclass with the @XmlRootElement annotation. 然后,用@XmlRootElement注释对每个子类进行注释。

My problem was in the interface class... 我的问题是在接口类...

I didn´t put annotation to map the fields 我没有添加注释来映射字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM