【发布时间】:2016-06-19 16:37:11
【问题描述】:
我想我有一个很常见的问题,但我找不到解决方案:(
我正在使用 spring 和 restTemplate 来恢复这样的 JSON 对象:
ResponseEntity<Download_urls> result= restTemplate.exchange(URL, HttpMethod.GET, entity, Download_urls.class);
“Download_urls”类里面有一个 JSON 数组:
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Download_urls {
private Video[] video;
}
和 Video.class
@JsonIgnoreProperties(ignoreUnknown = true)
public class Video {
private String type;
private String label;
private String file;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
}
显然 Video[] 无法映射 JSON 数组。有什么帮助吗?
谢谢
更新: 示例 JSON 有效负载:
{
"id": 737132,
"asset": {
"_class": "asset",
"id": 538362,
"download_urls": {
"Video": [{
"type": "video/mp4",
"label": "360"
}, {
"type": "video/mp4",
"label": "720"
}]
}
}
}
【问题讨论】:
-
您能否发布一个示例 JSON 有效负载?
-
当然@MichalFoksa !!是这样的: {"id": 737132, "asset": { "_class": "asset", "id": 538362, "download_urls": { "Video": [ {"type": "video/mp4 ", "label": "360"}, {"type": "video/mp4", "label": "720"}]}}} 我无法从 download_url 检索视频 JSON 数组 谢谢!
-
你定义了资产类及其外部类型(带有id和资产)吗?
-
是的,一切顺利,直到我尝试调试 Download_url 类时 Video 类变为 null。
-
从 Download_url 类中移除
@JsonIgnoreProperties(ignoreUnknown = true)。这会给你有用的信息什么是错的。
标签: arrays json jackson mapping resttemplate