spring boot scala 对象fastJson toJsonString 为空

发布于 / bug飞 / 0条评论 / Tags: java / 15 次浏览

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<String, String>.
  • 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)

    评论区(暂无评论)