Discuss / Java / 链式解析json报错

链式解析json报错

Topic source

不器

#1 Created at ... [Delete] [Delete and Lock User]

json文件里的key值author无法解析,报错

Cannot deserialize instance of `java.lang.String` out of START_OBJECT token

 at [Source: (FileInputStream); line: 4, column: 13] (through reference chain: org.example.Book["author"])

求解答。

不器

#2 Created at ... [Delete] [Delete and Lock User]

问题解决了,由于我的Bean里的author仍然String类型,而json文件解析出来应该是一个Object,

所以我创建了一个Author类:

@Datapublic class Author {    @JsonProperty("firstName")    private String firstName;    @JsonProperty("lastName")    private String lastName;}

完成解析

或者不另外创建类,在bean中对嵌套的json对象给一个注解

@JsonProperty("author")public JsonNode author;

完成解析

参考:https://stackoverflow.com/questions/19389723/can-not-deserialize-instance-of-java-lang-string-out-of-start-object-token


  • 1

Reply