我有这个JSON片段:
{
"uploadData": {
"25967391": {
"jobid": "jobId",
"numberOfFiles": "1",
"outputFiles": {
"1": "file.pdf"
},
"originalFiles": {
"1": "./target/test-classes/com/tools/myProject/input/File.pdf",
"2": "./target/test-classes/com/tools/myProject/input/File.csv"
}
}
}
}
我想做的是反序列化原始文件"进入地图。因为" 1"和" 2" in" originalFiles"都是非绝对URI我已经有了自定义类URIStringDeserializer
Paths.get(".").toUri().resolve(uriString).normalize().toASCIIString()
给了我
file:/C:/Users/userName/IdeaProjects/myProject/target/test-classes/com/tools/myProject/input/File.pdf
代表originalFiles
的第一个uri。
以下是包含uploadData
字段的类:
@JsonIgnoreProperties(ignoreUnknown = true)
public class UploadData{
@JsonProperty("originalFiles")
private Map<Integer, URI> originalFiles;
//getters and setters omitted
}
使用uploadData
注释@JsonDeserialize(using = CustomDeserializer.class)
字段会产生com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.net.URI out of START_OBJECT token
。如何让我的自定义反序列化程序使用tose map?
答案 0 :(得分:0)
经过一些外部帮助后,找到了解决方案。添加
@JsonDeserializer(contentUsing = CustomDeserializer.class)
做了我想做的事。