开发者

Does JAXB support inlined elements?

I noticed that Jackson has a pending feature for inlined/unwrapped elements, see here: http://wiki.fasterxml.com/JacksonRelease19.

The idea is tha开发者_JAVA技巧t you may have two classes:

class A {
    String y;
    String z;
}
class B {
    String x;
    A a;
}

And you want to produce JSON like:

{
    "x":"...",
    "y":"...",
    "z":"..."
}

The question is, does JAXB support some similar feature (or is it expected to at any point in the future)? I believe that normal inheritance can do this but since java doesn't support multiple inheritance this isn't always feasible (not to mention that the relationship might be more of a has-a rather than is-a).


Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.

MOXy currently supports this concept in its XML binding, and will support it in its JSON Binding via the @XmlPath extension (see below):

package forum7352753;

import org.eclipse.persistence.oxm.annotations.XmlPath;

class B {
    String x;
    A a;

    public String getX() {
        return x;
    }

    public void setX(String x) {
        this.x = x;
    }

    @XmlPath(".")
    public A getA() {
        return a;
    }

    public void setA(A a) {
        this.a = a;
    }

}

Enhancement Request

  • https://bugs.eclipse.org/357142

For More Information

  • http://blog.bdoughan.com/2010/07/xpath-based-mapping.html
  • http://blog.bdoughan.com/2011/08/json-binding-with-eclipselink-moxy.html
  • http://blog.bdoughan.com/2011/08/binding-to-json-xml-geocode-example.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜