REST API で Java を json に変換するために JAXB/Jersey (1.3) を使用しています。私はこの問題について多くのことを読みました、私はこの解決策を試しました、それは半分働きます:
@XmlRootElement
public class ArrayWrapper
{
public List<String> list = new LinkedList<String>();
}
と私の ContextResolver:
@Provider
public class JAXBContextResolver implements ContextResolver<JAXBContext> {
private JAXBContext context;
private Class[] types = {ArrayWrapper.class,Wrapper.class};
public JAXBContextResolver() throws Exception {
MappedBuilder builder = JSONConfiguration.mapped();
builder.arrays("list");
builder.rootUnwrapping(true);
this.context = new JSONJAXBContext(builder.build(), types);
}
ArrayWrapper aw=new ArrayWrapper();
aw.list.add("テスト");
{"list":["test"]} を取得するので動作しますが、ArrayWrapper を他のクラスでラップすると動作しません:
@XmlRootElement
public class Wrapper
{
public ArrayWrapper aw;
public Wrapper()
{
aw=new ArrayWrapper();
aw.list.add("test");
}
}
新しいラッパー();
{"aw":{"list":"test"}} を取得しました
誰でもそれを修正する方法を知っていますか?