I have following code, note that "r" and "?" are just shorthands for pickBranch so the JSON code is more readable:
val emptyObj = __.json.put(Json.obj())
def ?[A <: JsValue](jspath: JsPath)(r : Reads[A]) = (jspath.json.pickBranch(r) or emptyObj)
def r[A <: JsValue](jspath: JsPath)(r : Reads[A]) = jspath.json.pickBranch(r)
val invoiceRowJson = (
r(__ \ 'title)(Reads.of[JsString]) and
?(__ \ 'quantity)(Reads.of[JsNumber]) and
?(__ \ 'quantityUnit)(Reads.of[JsString]) and
?(__ \ 'price)(Reads.of[JsNumber]) and
?(__ \ 'tax)(Reads.of[JsNumber]) and
?(__ \ 'taxPrice)(Reads.of[JsNumber]) and
?(__ \ 'totalTaxPrice)(Reads.of[JsNumber]) and
?(__ \ 'totalPrice)(Reads.of[JsNumber])
).reduce
val invoiceJson = (
r(__ \ 'title)(Reads.of[JsString]) and
?(__ \ 'client)(Reads.of[JsString]) and
?(__ \ 'invoiceRows)(Reads.arr(invoiceRowJson)) // PSEUDO CODE "Reads.arr"
).reduce
See the PSEUDO code line (I've made up the Reads.arr). The problem: how can I do the reading of array of JsObjects of certain Reads?
Thanks.
- Jari