简体   繁体   English

如何在Jersey / JaxB中将嵌套集合从POJO打包为XML?

[英]How to marshal nested collections from POJO to XML in Jersey / JaxB?

I have two classes annotated as follows in Jersey v1.13: 在Jersey v1.13中,我有两个注释如下的类:

@XmlRootElement(name="request_pojo")
public class RequestPojo {
    public String name;

    @XmlElementWrapper(name = "nested_pojos")
    @XmlElement(name = "nested_pojo")
    public List<NestedPojo> nestedPojo;
}

@XmlRootElement(name="nested_pojo")
public class NestedPojo {
    public String name;
}

When I attempt to use Jersey client to serialize a RequestPojo that has a collection of NestedPojo s ... I don't see them being marshalled in the logs: 当我尝试使用Jersey客户端序列化RequestPojo具有集合NestedPojo小号......我不认为他们会在日志中被编组:

INFO: 1 * Client out-bound request
23:30:45 web.1  | 1 > POST https://localhost:443/test/
23:30:45 web.1  | 1 > Content-Type: application/xml
23:30:45 web.1  | <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                  <request_pojo>
                    <name>blah</name>
                  </request_pojo>

What do I have to fix in order to see something like the following being put onto the wire by the jersey client? 为了看到泽西客户将以下内容添加到网络中,我该如何解决?

<request_pojo>
  <name>blah</name>
  <nested_pojos>
    <nested_pojo>
      <name>nested blah</name>
    </nested_pojo>
  </nested_pojos>
</request_pojo>

As for me your code works well. 对于我来说,您的代码运行良好。
Possible problems: 可能的问题:
1) In your implementation of List iterator isn't implemented. 1)在您的List迭代器的实现没有实现。
2) nestedPojo is empty or null . 2) nestedPojo为空或null Debug project to check it 调试项目进行检查

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

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