membersound
membersound

Reputation: 86875

How to serialize a List with JAXB and XmlJavaTypeAdapter?

I have a List<String> that I want to serialize using JAXB. The list is also preprocessed by some XmlJavaTypeAdapter as follows:

@XmlElement(name = "category")
@XmlJavaTypeAdapter(AdapterXml.class) //for modifying some values inside the list during serialization
private List<String> categories;

Result:

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.util.List is an interface, and JAXB cannot process interfaces.
    this problem is related to the following location:
        at java.util.List

Why? How can I serialize the list?

Upvotes: 0

Views: 381

Answers (2)

membersound
membersound

Reputation: 86875

The solution was to use AdapterXml<ArrayList<String>, ArrayList<String>> instead of implementing just the List interface.

Upvotes: 1

Arvind Chavhan
Arvind Chavhan

Reputation: 488

You should not use annotation @XmlJavaTypeAdapter(AdapterXml.class). Try with below

@XmlElement(name = "category")
//for modifying some values inside the no need any special type of annotation.
list during serialization
private List<String> categories;

Upvotes: 0

Related Questions