【问题标题】:Failed to evaluate Jackson deserialization无法评估 Jackson 反序列化
【发布时间】:2018-11-14 05:09:22
【问题描述】:

添加到我的 DTO 对象后,我想向服务器发送一个列表

private ImmutableList<T> elementsToAdd;

来自

import com.google.common.collect.ImmutableList;

当发送一个对象到它抛出的控制器时

2018-06-04 21:41:31.645  WARN 508 --- [nio-8443-exec-6] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.jonki.popcorn.common.dto.request.ContributionNewRequest<com.jonki.popcorn.common.dto.movie.Language>]]: com.fasterxml.jackson.databind.JsonMappingException: Cannot find a deserializer for non-concrete Collection type [collection type; class com.google.common.collect.ImmutableList, contains [simple type, class com.jonki.popcorn.common.dto.movie.Language]]

【问题讨论】:

  • Jackson 需要一个具体的类型,而不是 T。
  • 我不能为泛型类型做ImmutableList 吗?但是 Jackson 可以识别泛型类型 [collection type; class com.google.common.collect.ImmutableList, contains [simple type, class com.jonki.popcorn.common.dto.movie.Language]] 下的内容。

标签: java json spring spring-mvc spring-boot


【解决方案1】:

您需要配置 Jackson,以便它可以序列化/反序列化 Guava 的不可变集合。见https://github.com/FasterXML/jackson-datatypes-collections/tree/master/guava

【讨论】:

猜你喜欢
  • 2023-04-11
  • 2020-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-25
  • 2020-09-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多