开发者

Converting List wrapper to List using JAXB

I'm trying to annotate a set of data objects with JAXB binding annotations so that this set of data objects can be properly marshaled as JSON using CXF. I'm running into an issue with a class that is basically just a wrapper around ArrayList:

class IntegerListWrapper {
    private ArrayList<Integer> integerList;
    ...
}

Some of my data objects refer to this class:

class DataObjectFoo {
    ...
    public IntegerListWrapper getDataIDs() {
        ...
    }
    ...
}

I'm looking for the output to be:

"DataObjectFoo" : {
  "dataID开发者_开发问答s" : [1, 2, ..., n] // Array of Data IDs
}

I tried annotating the IDList class itself but it left me with this:

"DataObjectFoo" : {
  "dataIDs" : { "integerList" : [1, 2, ..., n] } // Extra nesting
}

I tried writing an XmlAdapter but got mixed results:

// Throws an error... "Can't bind to interface"
public final class IDListAdapter extends XmlAdapter<List<Integer>, IDList> {
// Does not produce any output
public final class IDListAdapter extends XmlAdapter<ArrayList<Integer>, IDList> {
// Produces output with extra nesting like above
public final class IDListAdapter extends XmlAdapter<Integer[]>, IDList>

So I have two questions:

  1. How do I get the desired output (without converting IDList to something else in my data objects)?
  2. Why did the second XmlAdapter (using ArrayList) not produce output?


I'm not sure you can with the extra wrapper class around it. Can you not just make the "getDataIds()" call return List?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜