这篇文章上次修改于 2217 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

spring boot自带的json converter和fastjson对scala生成的对象,都不能很好的序列化成json。结果都会为空

解决办法:
[1] 需要序列化的类型,用kotlin定义.毕竟kotlin和scala的类定义语法基本相同
[2] 使用或者替换fastjson或者springboot的http message converter.如替换为json4s
[3] 附录:spring boot默认的converter如下:

  • ByteArrayHttpMessageConverter – converts byte arrays
  • StringHttpMessageConverter – converts Strings
  • ResourceHttpMessageConverter – converts org.springframework.core.io.Resource for any type of octet stream
  • SourceHttpMessageConverter – converts javax.xml.transform.Source
  • FormHttpMessageConverter – converts form data to/from a MultiValueMap.
  • Jaxb2RootElementHttpMessageConverter – converts Java objects to/from XML (added only if JAXB2 is present on the classpath)
  • MappingJackson2HttpMessageConverter – converts JSON (added only if Jackson 2 is present on the classpath)
  • MappingJacksonHttpMessageConverter – converts JSON (added only if Jackson is present on the classpath)
  • AtomFeedHttpMessageConverter – converts Atom feeds (added only if Rome is present on the classpath)
  • RssChannelHttpMessageConverter – converts RSS feeds (added only if Rome is present on the classpath)