java - 使用 XStream 反序列化顺序和动态元素
问题描述
我需要反序列化具有动态和顺序元素的 XML。
我正在使用 XStream 1.4。
有没有办法使用注释转换为通用列表?还是我需要扩展转换器?
- XML
示例 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
解决方案
推荐阅读
- php - Podio 在尝试添加在其字段中具有多个标签的项目时抛出 PodioBadRequestError invalid_value int
- excel - 在 VBA 中使用循环删除范围并在每次迭代时更改范围
- python - VsCode 在运行模式和调试模式之间的不同行为
- javascript - 如何使此代码仅显示 600px 及以上?(我不希望它出现在手机或平板电脑上)
- swift - 搜索栏必须显示一个结果,其中每个都必须包含所有搜索的单词,而不管它们的编写顺序如何?
- sql - SQL SERVER 替换空值
- flutter - SingleChildScrollView 显示白色
- javascript - 在创建 API 时修改了来自 nestjs 的 JSON 响应
- linq - LINQ 查询以获取学生课程
- apache-atlas - Apache Atlas:从 Java 客户端连接时出现 Http 503 Service Unavailable 错误