2015-09-29 59 views
0

我有一個List<String>,我想要序列化使用JAXB。該名單也被一些XmlJavaTypeAdapter預處理如下:如何使用JAXB和XmlJavaTypeAdapter序列化List?

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

結果:

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 

爲什麼?我如何序列化列表?

回答

0

您不應該使用註釋@XmlJavaTypeAdapter(AdapterXml.class)。試試下面

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

我確實需要'XmlJavaTypeAdapter'來轉換列表中的值(爲列表中的每個字符串添加後綴和後綴)。所以我*不能*刪除它! – membersound

1

的解決方案是使用AdapterXml<ArrayList<String>, ArrayList<String>>,而不是僅僅實現List接口。

相關問題