[英]How to serialize a List with JAXB and XmlJavaTypeAdapter?
I have a List<String>
that I want to serialize using JAXB
. 我有一个List<String>
我想使用JAXB
进行序列化。 The list is also preprocessed by some XmlJavaTypeAdapter
as follows: 某些XmlJavaTypeAdapter
也对该列表进行了预处理,如下所示:
@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? 如何序列化列表?
解决方案是使用AdapterXml<ArrayList<String>, ArrayList<String>>
而不是仅实现List
接口。
You should not use annotation @XmlJavaTypeAdapter(AdapterXml.class). 您不应使用注释@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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.