1、scala中case class 转json问题
java中对象转json有很多方法,但是使用java中的转换方法来转换scala对象会出现编译报错的情况。
scala中对象转json str可以尝试下面方法:
pom.xml
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-native_2.11</artifactId>
<version>3.5.4</version>
</dependency>
// sendMessage 为样例类、map
import org.json4s.native.Serialization
implicit val formats: DefaultFormats.type = org.json4s.DefaultFormats
val sendMsg: String = Serialization.write(sendMessage)