问题描述SpringCloud通过Feign客户端调用HTTP接口,如果返回值中包含LocalDateTime类型(包括其他JSR-310中java.time包的时间类)),在客户端端可能会出现反序列化失败的错误。错误信息如下:feign.codec.DecodeException:Typedefinitionerror:[simpletype,classjava.time.LocalDateTime];嵌套异常是com.fasterxml.jackson.databind.exc.InvalidDefinitionException:无法构造`java.time.LocalDateTime`的实例(不存在Creator,如默认构造):没有可从String值反序列化的字符串参数构造函数/工厂方法('2019-11-27T11:04:32')引起:org.springframework.http.converter.HttpMessageConversionException:类型定义错误:[简单类型,类java.time.LocalDateTime];嵌套异常是com.fasterxml.jackson.databind.exc.InvalidDefinitionException:无法构造`java.time.LocalDateTime`的实例(不存在Creator,如默认构造):没有可从String值反序列化的字符串参数构造函数/工厂方法('2019-11-27T11:04:32')引起:com.fasterxml.jackson.databind.exc.InvalidDefinitionException:无法构造`java.time.LocalDateTime`的实例(无Creators,likedefaultconstruct,exist):noString-argumentconstructor/factorymethodtodeserializefromStringvalue('2019-11-27T11:04:32')问题分析搜索了一个类似的问题:http://blog.didispace.com/Spring-Boot-And-Feign-Use-localdate/,但是文章提供的方法并没有解决问题经测试,SpringCloud的HTTP接口的参数或返回值中的LocalDateTime类型可以正常序列化并且反序列化,但是通过Feign客户端调用,反序列化时可能会出错。跟踪代码发现Feign客户端通过feign.codec.Decoder接口的实现类SpringDecoder反序列化,最后调用了org.springframework.http.converter.json.MappingJackson2HttpMessageConverter,这是SpringMVC默认使用的HttpMessageConverter,所以一样converter在不同的调用方式下产生不同的结果还不得而知。问题解决增加依赖
