How to convert Scala Map into JSON String?

前端 未结 7 1786
一向
一向 2021-02-07 04:19

For example, I have this Map value in Scala:

val m = Map(
    \"name\" -> \"john doe\", 
    \"age\" -> 18, 
    \"hasChild\" -> true, 
    \"childs\" -         


        
7条回答
  •  礼貌的吻别
    2021-02-07 04:44

    val mapper = new ObjectMapper()
    mapper.writeValueAsString(Map("a" -> 1))
    

    result> {"empty":false,"traversableAgain":true}

    ==============================

    import com.fasterxml.jackson.module.scala.DefaultScalaModule
    
    val mapper = new ObjectMapper()
    mapper.registerModule(DefaultScalaModule)
    mapper.writeValueAsString(Map("a" -> 1))
    

    result> {"a":1}

提交回复
热议问题