tags:

views:

44

answers:

1

I have two similar classes, that simply have a string name. I wanted to add an XML adapter to the Lists so that I could get a CSV string from each of them.

I tried to declare my adapter like so:

 public class ListXmlAdapter extends XmlAdapter<String, ArrayList<Object>> {

But when I try to use this I get illegal annotation exceptions saying ListXmlAdapter is not applicable for whatever type I try to pass in at the annotation - such as Test below

@XmlElement
@XmlJavaTypeAdapter(ListXmlAdapter.class)
List<Test> tests = new ArrayList<Test>()

How would I create this adapter that I want to use for a few different ArrayLists of different object types I have?

A: 

If you change the property type to ArrayList it will work:

@XmlElement
@XmlJavaTypeAdapter(ListXmlAdapter.class)
ArrayList<Test> tests = new ArrayList<Test>();
Blaise Doughan
I am working in a legacy application here. Will this have any other side-effects?
Derek
Turns out this broke the rest of my code when I changed this to an ArrayList - I got some deletion/creation errors. I will post the exact error later if I can't get it
Derek
posted this as a new question here: http://stackoverflow.com/questions/3962875/dataintegrityviolationexception-when-i-change-a-list-variable-to-arraylist
Derek
We are working on a fix in MOXy JAXB that would let you use List instead of ArrayList for this case. You can track the issue with the following bug: https://bugs.eclipse.org/328079
Blaise Doughan