title: Transforming Scala case class into JSON
body: <p>I have two case classes. The main one, <code>Request</code>, contains two maps.
  The first map has a string for both key and value.
  The second map has a string key, and value which is an instance of the second case class, <code>KVMapList</code>.</p>
  
  <pre><code>case class Request (var parameters:MutableMap[String, String] = MutableMap[String, String](), var deps:MutableMap[String, KVMapList] = MutableMap[String, KVMapList]())
  
  case class KVMapList(kvMap:MutableMap[String, String], list:ListBuffer[MutableMap[String, String]])
  </code></pre>
  
  <p>The requirement is to transform <code>Request</code> into a JSON representation.
  The following code is trying to do this:</p>
  
  <pre><code>import com.fasterxml.jackson.annotation.PropertyAccessor
  import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
  import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility
  import com.fasterxml.jackson.databind.ObjectMapper
  
  def test(req:Request):String {
    val mapper = new ObjectMapper() with ScalaObjectMapper
    mapper.setVisibility(PropertyAccessor.ALL,  Visibility.ANY)
    var jsonInString: String = null
    try {
      jsonInString = mapper.writeValueAsString(request)
    }
    catch {
      =case e: IOException =&gt; {
        e.printStackTrace
     }
    jsonString
  }
  </code></pre>
  
  <p>This however is not working. Even when the <code>Request</code> class is populated, the output is :</p>
  
  <pre><code>{"parameters":{"underlying":{"some-value":""},"empty":false,"traversableAgain":true},"deps":{"sizeMapDefined":false,"empty":false,"traversableAgain":true}}
  </code></pre>
  
  <p>Using the JSON object mapper with corresponding Java classes is straightforward, but have not yet got it working in Scala. Any assistance is very much appreciated.</p>