具有自定义拦截器的JAXB解组器? [英] JAXB unmarshaller with custom interceptor?
本文介绍了具有自定义拦截器的JAXB解组器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以拦截" JAXB
的解组过程?
Is it possible to "intercept" the unmarshalling process of JAXB
?
我有一个xml响应,应该将其部分转换为不同的java字段结构:
I have an xml reponse that partially should be converted to a different java fields structure:
<xml>
<X_FIELD1></X_FIELD1>
<X_FIELD2></X_FIELD2>
...
<X_FIELD11></X_FIELD11>
</xml>
在我的java类中,我希望将其解组为List<String>
,而不是11个String
字段.
In my java class, I'd prefer to unmarshal this to a List<String>
, instead of 11 String
fields.
public class XmlResponse {
private String X_FIELD1;
private String X_FIELD2;
//...
private String X_FIELD11;
// private List<String> xFields;
}
但这有可能吗?
推荐答案
您应使用自定义xml适配器
You should use a custom xml adapter
http://docs. oracle.com/javaee/5/api/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html
http://docs. oracle.com/javaee/5/api/javax/xml/bind/annotation/adapters/XmlAdapter.html
在类级别应用它并实现适配器.
apply it on the class level and implement the adapter.
这篇关于具有自定义拦截器的JAXB解组器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文