score:0

From the source code, it looks like only nested extraction of simple values is supported. Details below.

You can extract values from Json using nested paths:

  val name: Field[String] = asType[String]("keyword.name")

This will extract 'test' from this json:

{keyword:{name:'test'}}

You can look for the code of this extraction in the class org.scalatra.json.JsonValueReader. This reader is used in the method org.scalatra.commands.Command.bindTo.

The critical source is:

...
      val result = b.field.valueSource match {
        case ValueSource.Body => fieldBinding(data.read(name).right.map(_ map (_.asInstanceOf[fieldBinding.S])))
...

The call "_.asInstanceOf[fieldBinding.S]" is realized on a JValue object. This extraction only work for simple types (check this question: How to parse JSON in Scala using standard Scala classes?).


Related Query

More Query from same tag