【发布时间】:2015-08-12 04:56:12
【问题描述】:
我必须使用@class 中的信息实例化一个从 JSON 扩展抽象类的类,如下所示。
"name": {
"health": "xxx",
"animal": {
"_class": "com.example.Dog",
"height" : "20"
"color" : "white"
}
},
这里的抽象类是animal,而dog扩展了animal类。那么使用@class中的信息,我们可以直接实例化dog。这也是我在 restTemplate 中得到的响应
ResponseEntity<List<SomeListName>> response = restTemplate.exchange("http://10.150.15.172:8080/agencies", HttpMethod.GET, request, responseType);
执行此行时出现以下错误。 由于 POJO 类是自动生成的,我不能使用像 @JsonTypeInfo
这样的注释我正在使用 Spring Boot 和 Maven。 控制台出现此错误。
无法读取 JSON:无法构造“MyPOJO”的实例,问题:抽象类型要么需要映射到具体类型,要么具有自定义反序列化器,要么使用额外的类型信息进行实例化
【问题讨论】:
标签: java jackson spring-boot deserialization resttemplate