I am trying to annotate a set of data objects using JAXB binding annotations so that this set of data objects can be correctly marshaled as JSON using CXF. I ran into a problem with a class, which basically is a wrapper around an ArrayList:
class IntegerListWrapper {
private ArrayList<Integer> integerList;
...
}
Some of my data objects belong to this class:
class DataObjectFoo {
...
public IntegerListWrapper getDataIDs() {
...
}
...
}
I am looking for a way out:
"DataObjectFoo" : {
"dataIDs" : [1, 2, ..., n] // Array of Data IDs
}
I tried annotating the IDList class, but it left me with this:
"DataObjectFoo" : {
"dataIDs" : { "integerList" : [1, 2, ..., n] }
}
I tried writing an XmlAdapter, but got mixed results:
public final class IDListAdapter extends XmlAdapter<List<Integer>, IDList> {
public final class IDListAdapter extends XmlAdapter<ArrayList<Integer>, IDList> {
public final class IDListAdapter extends XmlAdapter<Integer[]>, IDList>
I have two questions:
- How to get the desired result (without converting IDList to something else in my data objects)?
- Why didn't the second XmlAdapter (using ArrayList) produce a result?