奇怪的XML混合XMLJAXBJSON编组/解编与MOXy
我有以下类型,在模式中定义为: 当我将此XML解组到JAXB对象时:奇怪的XML混合XMLJAXBJSON编组/解编与MOXy,jaxb,moxy,Jaxb,Moxy,我有以下类型,在模式中定义为: 当我将此XML解组到JAXB对象时: <FORM_OF_COOWNERS> <add_info> <info_analytics> <issuer_subdiv> <id><id>1940001</id></id> </issuer_subdiv> <fl
<FORM_OF_COOWNERS>
<add_info>
<info_analytics>
<issuer_subdiv>
<id><id>1940001</id></id>
</issuer_subdiv>
<fl_worker>Yes</fl_worker>
</info_analytics>
</add_info>
</FORM_OF_COOWNERS>
这份名单是从哪里来的?info_analytics映射到没有任何集合/数组的类型
如果我得到这个JSON,umarshall将它转换成JAXB对象,marshall转换成XML,它将生成:
<info_analytics fl_worker="Yes">
<issuer_subdiv>
<id id="1940001">
<id>1940001</id>
</id>
</issuer_subdiv>
<fl_worker>Yes</fl_worker>
</info_analytics>
xml:
受保护的静态同步JAXBContext getContext{
如果jaxbContext==null
试一试{
jaxbContext=jaxbContext.newInstanceorg.example.models;
}捕获JAXBEException异常{
抛出新的RuntimeExceptionex;
}
返回jaxbContext;
}
public static void saveMessageObject msg,OutputStream os抛出jaxbeexception{
Marshaller-Marshaller=getContext.createMarshaller;
marshaller.marshallmsg,操作系统;
}
公共静态对象loadMessageInputStream是JaxBeException{
Unmarshaller Unmarshaller=getContext.createUnmarshaller;
返回unmarshaller.unmarshalis;
}
我不确定这种奇怪的往返需要多长时间:XML->Java->JSON->Java->XML。我想您应该理解,XML支持的特性比JSON多得多,这就是为什么不可能总是有1对1的映射
如果这对您来说是一个真正的问题,而不仅仅是理论研究,请针对MOXy启动一个bug:您可以添加更多详细信息吗?e、 g.封送和解封送代码,创建对象,etcIt的纯实践调查。作为解决方法,我最终编写了一些更强类型的类和适配器,从这个类到/从AnyT
{"FORM_OF_COOWNERS":{"add_info":{"info_analytics":[{"issuer_subdiv":{"id":{"id":"1940001"}},"fl_worker":"Yes"}]}}}
<info_analytics fl_worker="Yes">
<issuer_subdiv>
<id id="1940001">
<id>1940001</id>
</id>
</issuer_subdiv>
<fl_worker>Yes</fl_worker>
</info_analytics>