[英]Deserializing XML @Element and @ElementList with same name from different XML datasets
I want to deserialize different sets of XML serialized data into one class (not at the same time) using SimpleXML . 我想使用SimpleXML将不同系列的XML序列化数据反序列化为一个类(而不是同时)。
All of the datasets have a root class of <body/>
, but different subclasses. 所有数据集的根类均为<body/>
,但子类不同。 Some have one element of <prediction>
, other multiple elements of <prediction>
. 一些具有一个元素<prediction>
,的其他多个元件<prediction>
。 Same for <route>
. 与<route>
相同。 This is the code I currently use, but it gives me an error of type PersistenceException
("Duplicate annotation"). 这是我当前使用的代码,但是它给我一个PersistenceException
类型的错误(“重复注释”)。
What would be the simplest way to solve this? 解决这个问题的最简单方法是什么? Any help would be appreciated. 任何帮助,将不胜感激。
@Root(name = "body", strict = false)
class NextBusAPIResult {
@Attribute(name = "copyright")
public String Copyright;
@Element(name = "predictions", required = false, type = Predictions.class)
public Predictions Predictions;
@ElementList(name = "predictions", required = false, inline = true)
public List<Predictions> PredictionsForMultiStops;
@Element(name = "route", required = false, type = RouteInfo.class)
public RouteInfo RouteInfo;
@ElementList(name = "route", required = false, inline = true)
public List<RouteSchedule> RouteSchedules;
}
The simplest way to solve this is to use multiple elements always. 解决此问题的最简单方法是始终使用多个元素。 Just remove code related to single elements. 只需删除与单个元素相关的代码即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.