MOXy停止使用XML注释序列化
将其序列化为JSON在MOXy 2.5.0中效果良好:MOXy停止使用XML注释序列化,xml,json,jaxb,jersey,moxy,Xml,Json,Jaxb,Jersey,Moxy,将其序列化为JSON在MOXy 2.5.0中效果良好: public Object[] destination_addresses; 但为了能够用JAXB(?)将其序列化为XML,我需要一个注释: @XmlElements({@XmlElement(name = "destination_address", type = LatLong.class), @XmlElement(name = "destination_address", type = Polygon
public Object[] destination_addresses;
但为了能够用JAXB(?)将其序列化为XML,我需要一个注释:
@XmlElements({@XmlElement(name = "destination_address", type = LatLong.class),
@XmlElement(name = "destination_address", type = Polygon.class)})
public Object[] destination_addresses;
但是MOXy根本没有序列化它。我怎样才能让它与MOXy和JAXB一起序列化?我用的是泽西2.4.1
MOXy和JAXB按预期工作(JAXB无法序列化LatLong),具有:
(我对这一切都不熟悉,所以如果我遗漏了有用的信息,请告诉我。)
编辑:不确定莫西为什么会在意,但这里是LatLong&Polygon:
public class LatLong {
public double lat, lng;
}
public class Polygon {
@XmlElement
protected List<LatLong> points = new ArrayList<LatLong>();
public String toString(){return points.toString();}
}
EDIT3:我将Polygon
恢复原样(即忽略EDIT2),在MOXy中发现了一个不相关的bug(见下面的评论),并将目标地址更改为列表
,而不是对象[]
<代码>多边形
现在可以序列化(使用点
),但简单的LatLong
根本不序列化
EDIT4:调试MOXy非常痛苦。我发现它将
LatLong
和Polygon
序列化为两个单独的数组,称为destination\u address
,而不是将它们都放在一个数组中。你的LatLong
和Polygon
类看起来像什么?@BlaiseDoughan我已经添加了它们。MOXy使用toString()进行序列化,而JAXB序列化XmlElement。@BlaiseDoughan我已经完全更改了多边形
,现在MOXy抛出了一个异常,我没有understand@BlaiseDoughan在xmlcooiceobjectmappingnodevalue.java
的第141行:那应该是class
而不是valueClass
?
public class LatLong {
public double lat, lng;
}
public class Polygon {
@XmlElement
protected List<LatLong> points = new ArrayList<LatLong>();
public String toString(){return points.toString();}
}
Exception [EclipseLink-60] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [] or [getLatOrLongs] is not defined in the object [com.buzzhives.Routing.Hive.Polygon].
Internal Exception: java.lang.NoSuchMethodException: com.buzzhives.Routing.Hive.Polygon.([Lcom.buzzhives.Routing.Hive.Polygon$LatOrLong;)
Mapping: org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping[latOrLongs]
Descriptor: XMLDescriptor(com.buzzhives.Routing.Hive.Polygon --> [])
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:689)