开发者

Bean-To-XML annotations: how to process nested structure

开发者 https://www.devze.com 2022-12-19 17:10 出处:网络
For bean->xml convertion in webservices we use Aegis from CXF (it is jaxb-compatible, as I understand).

For bean->xml convertion in webservices we use Aegis from CXF (it is jaxb-compatible, as I understand).

This is my type:

class C{
private int a;
private int b;
private T t;
...
}

class T{
private int t1;
private int t2;
}

I need t.t1 field to be on the same level in XML as a and b in C (bean restored from xml should be like this:

class C{ 
private开发者_Go百科 int a; 
private int b;
private int t1 
}

(client code is interested only in field t1 from structure T). Thanks.


You could add getT1() and setT1(int) to C and make getT() @XmlTransient

class C {
  // snip

  /**
   * JAXB only
   */
  @SuppressWarnings("unused")
  @XmlElement
  private void setT1(int t1) {
    if(t != null) {
      t.setT1(t1);
    } else {
      // TODO
    }
  }

  /**
   * JAXB only
   */
  @SuppressWarnings("unused")
  private int getT1() {
    if(t != null) {
      return t.getT1(t1);
    } else {
      // TODO
    }
  }
}
0

精彩评论

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

关注公众号