简体   繁体   中英

JAXB equivalent of the JPA @Embdedded annotation

have a quick question:

I have the following two classes.

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Customer {

  @XmlElement(name = "name")
  private String name;

  @XmlElement(name = "address")
  private Address address;

}

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Address {

  @XmlElement(name = "post_code")
  private String postCode;

  @XmlElement(name = "country")
  private String country;
}

This produces the following JSON:

{ 
  "name" : "john",
  "address" : {
      "post_code" : "XYZ 123",
      "country" : "US"
  }
}

But I actually want something more like this (so its similar in nature to the @Embedded in JPA):

{ 
  "name" : "john",
  "post_code" : "XYZ 123",
  "country" : "US"
}

So the embedded object fields are 'pulled up'. I noticed on stackoverflow, it was mentioned that you can use MOXy's @XmlPath(".") to do this. But is there no way from the standard java EE spec to do this and not a MOXy specific annotation?

从JAXB 2.2开始,目前没有标准的JAXB(JSR-222)注释可以完成EclipseLink JAXB(MOXy)@XmlPath(".")注释可以完成的工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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