title: Playframework: How do I bind JSON to case class that contains a map?
body: <p>I'm using Playframework 2.2.1 with Scala, and I'm writing a REST API where users can set partially unstructured data. Basically, users will POST JSON that looks something like this:</p>
  
  <pre><code>{
    "id": 1,
    "name": "MyObject",
    "properties": [
      "myFirstProperty": "Value 1",
      "mySecondProperty": "Value 2"
    ]
  }
  </code></pre>
  
  <p>and I want it to bind to a case class that looks like:</p>
  
  <pre><code>case class Preference(id: Long, name: String, properties: Map[String, String])
  </code></pre>
  
  <p>I am hoping to take advantage of Play's forms API for that so I can have a bunch of nice validation options for free, but I haven't been able to figure out a straightforward way to do that. Ideally (at least in my mind), I would be able to define a Form object along the lines of:</p>
  
  <pre><code>Form(
    mapping(
      "id" -&gt; longNumber,
      "name" -&gt; nonEmptyText(min = 5),
      "properties" -&gt; map(nonEmptyText, nonEmptyText)
    )(Preference.apply)(Preference.unapply)
  )
  </code></pre>
  
  <p>Unfortunately, the "map(text, text)" is fictional. Has anyone done a similar binding to this using the forms API? If so, how? If not, I'm curious what you used instead for validation. Was it all done by hand?</p>
  
  <p>Thanks in advance for the help!</p>