java - JSON 未命名集合到 Java (jackson ObjectMapper)
问题描述
我尝试寻找类似的问题,发现了这个Use Jackson to parse and unnamed array
但是,我有一个问题。我的 JSON 在第 N 级上有这个未命名的数组 - 非常简化的版本:
{
"section":{
"ID":"",
"code":{
"code":"",
"codeSystem":"",
"codeSystemName":""
},
"entry":[
{
"act":{
"classCode":"",
"entryRelationship":{
"name":""
}
},
"id":""
},
{
"act":{
"classCode":"",
"entryRelationship":{
"name":""
}
},
"id":""
}
]
}
}
还有比section更高的级别,但这应该是主要问题。我有这个“入口”键,它可以有多个“行为”和“id”(作为未命名对象的属性)。我已经在使用 jackson 库中的 ObjectMapper 和 @JsonProperty 工具,我想保持干净。该部分的一段代码(同样,非常简化):
public class ComponentSection {
@JsonProperty("ID")
private String id;
@JsonProperty("code")
private Code code;
@JsonProperty("entry")
private SectionEntry entry;
}
我能做些什么来映射这个 JSON 吗?
谢谢!
解决方案
改变
@JsonProperty("entry")
private SectionEntry entry;
至
@JsonProperty("entry")
private List<SectionEntry> entry;
推荐阅读
- cluster-analysis - 为 Kmeans 聚类选择 K 值
- window - 在 Windows 10 中找不到 Inf2Cat
- swift - 让听众知道何时在 dynamodb 中更新了令人兴奋的项目
- asp.net-core-webapi - LINQ 查询仅选择内部列表(JSON 响应中的问题)
- azure - 如何将标签添加到在 Microsoft Azure 中创建的文件存储、队列存储和表存储
- python - 如何在使用 python 的不同客户的特定月数后计算出平均值?
- json - 带有 GraphQL 解析错误的 Google Apps 脚本 API 请求
- java - 程序计算 1250 小时后的时间?
- javascript - 如何获取作为标头添加的值以响应从服务器到客户端(在 reactjs 中)?
- oracle-apex - 如何获取项目“数据库列”名称