我需要反序列化具有动态和顺序元素的XML。
我正在使用XStream 1.4。
有什么方法可以使用注释转换为通用列表?还是我需要扩展Converter?
示例1:
<entities>
<entity>
<f0>RECIFE</f0>
<f1>13/01/2017 13:58:47</f1>
</entity>
<entity>
<f0>TERESINA</f0>
<f1>13/01/2018 13:58:47</f1>
</entity>
</entities>
示例2:
<entities>
<entity>
<f0>RECIFE</f0>
<f1>13/01/2017 13:58:47</f1>
<f2>36ºC</f2>
</entity>
<entity>
<f0>TERESINA</f0>
<f1>13/01/2018 13:58:47</f1>
<f2>42ºC</f2>
</entity>
</entities>
@XStreamAlias("entities")
public class EntitiesResponse {
@XStreamImplicit(itemFieldName = "entity")
private List<EntityResponse> entity;
// getters and setters
}
@XStreamAlias("entity")
@XStreamConverter(value = SerializableConverter.class, strings = {"value"})
public class EntityResponse {
private Object value;
// getters and setters
}
Security framework of XStream not initialized, XStream is probably vulnerable.
Exception in thread "main" com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field com.mycompany.mavenproject1.response.EntityResponse.f0
---- Debugging information ----
message : No such field com.mycompany.mavenproject1.response.EntityResponse.f0
field : f0
class : com.mycompany.mavenproject1.response.EntityResponse
required-type : com.mycompany.mavenproject1.response.EntityResponse
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /entities/entity/f0
class[1] : com.mycompany.mavenproject1.response.EntitiesResponse
required-type[1] : com.mycompany.mavenproject1.response.EntitiesResponse
version : 1.4.11.1