feign.codec.DecodeException: Error while extracting response for type [java.util.List<A
feign.codec.DecodeException: Error while extracting response for type [java.util.List<entity.BasicDeviceWorkwearConstraint>] and content type [application/json;charset=UTF-8]
- 核心问题 :
- 问题出在Extendable 类的 getExtension() 方法上
- 该方法总是返回一个新的 HashMap 对象,而不是在 extension 为 null 时返回 null
- 这导致 Feign 客户端在解析 JSON 响应时出现类型不匹配问题
- 详细原因链 :
- 当 BasicDeviceWorkwearConstraintController 返回 List<BasicDeviceWorkwearConstraint> 时
- 统一结果集包装器 ( ResponseWrapperAdvice ) 会将结果包装为 ResultVO.success(body)
- 当 Jackson 序列化 BasicDeviceWorkwearConstraint 对象时,会调用 getExtension() 方法
- 由于 getExtension() 总是返回 HashMap (即使原始值为 null ),Jackson 会将其序列化为空的 JSON 对象 {}
- Feign 客户端在解析时期望得到与接口定义一致的类型,但实际得到了包含额外空对象的响应
- 这导致了 feign.codec.DecodeException 异常
当Feign客户端尝试将JSON响应解析为 List<BasicDeviceWorkwearConstraint> 时:
- 首先,它期望的是一个JSON数组,但实际得到的是一个JSON对象(包含code、msg、data字段)
- 其次,即使能跳过包装(有@IgnoreResponseWrapper注解),每个BasicDeviceWorkwearConstraint对象中的extension字段是一个空对象{},而不是预期的可能为null的Map
这就导致了 feign.codec.DecodeException 异常:
更多推荐




所有评论(0)