title: Deserialize Scala map field from JSON using Jackson
body: <p>I'm trying to serialize/deserialize a Scala class to JSON using Jackson ObjectMapper. The serialization works fine, but I was getting type exceptions trying to read the JSON back in. I fixed most of those by adding appropriate annotations, but it's not working for my Map members... it seems like Jackson is trying to treat the keys in the JSON object as properties in a class instead of keys in a map. (I believe this is different than other questions like this one since they are calling <code>readValue</code> on the map contents directly.)</p>
  
  <p>Here's my ObjectMapper setup:</p>
  
  <pre><code>val mapper = new ObjectMapper() with ScalaObjectMapper
  mapper.registerModule(DefaultScalaModule)
  </code></pre>
  
  <p>Here's what my annotated class and member look like:</p>
  
  <pre><code>@JsonInclude(JsonInclude.Include.NON_DEFAULT)
  class MyClass extends Serializable {
    @JsonDeserialize(
      as = classOf[mutable.HashMap[String, Long]],
      keyAs = classOf[java.lang.String],
      contentAs = classOf[java.lang.Long]
    )
    val counts = mutable.Map.empty[String, Long]
  }
  </code></pre>
  
  <p>If I give it some JSON like:</p>
  
  <pre><code>{"counts":{"foo":1,"bar":2}}
  </code></pre>
  
  <p>And read it with <code>mapper.readValue[MyClass](jsonString)</code></p>
  
  <p>I get an exception like <code>UnrecognizedPropertyException: Unrecognized field "foo" (class mutable.HashMap), not marked as ignorable</code>.</p>
  
  <p>I tried adding <code>DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES</code> to my mapper configuration but that didn't seem to do anything in this case, and I'm not sure that kind of global setting is desirable.</p>
  
  <p>How do I convince Jackson to treat the strings "foo" and "bar" as keys in the map member field and not as properties in the HashMap class? It seems to have done the right thing automatically writing it out.</p>
  
  <p>Also worth noting: the deserialization appears to work fine in a quick out/in unit test to a temp file or a string variable, but not when I try to run the whole application and it reads the JSON its previously written. I don't know why it seems to work in the test, as far as I know it's making the same <code>readValue</code> call.</p>