How can I pick only existing JSON branches in Play 2.4 (Scala)? -


edited question (simplified)

i input json object via rest api , want transform new validated json object. properties/branches optional.

my play 2.4 action far:

import play.api.mvc._ import play.api.libs.json._ import play.api.libs.json.reads._ import play.api.libs.functional.syntax._  // [...]  def updateuser(id: string) = action(parse.json) { request =>     /** name validaton */     val namereads: reads[jsstring] = reads.of[jsstring] keepand         reads.minlength[string](2) keepand         reads.maxlength[string](20) keepand         reads.pattern("""[a-z]*""".r)      /** age validaton */     val agereads: reads[jsnumber] = reads.of[jsnumber] keepand         reads.min(18) keepand         reads.max(128)      /** transformer */     val transformuser: reads[jsobject] = (         (__ \ 'name).json.pickbranch(namereads) ,         (__ \ 'age).json.pickbranch(agereads)     ).reduce      // guess i'd have this:     // val transformuser: reads[jsobject] = (     //  (__ \ 'name).json.pickbranchifexists(namereads) ,     //  (__ \ 'age).json.pickbranchifexists(agereads)     // ).reduce      val inputjson: jsvalue = request.body     inputjson.transform(transformuser).map { resultjsobj =>         ok(resultjsobj)     } recovertotal { err =>         val errjsobj: jsobject = jserror.tojson(err)         badrequest(errjsobj)     } } 

now i'm looking neither pickbranch, nor prune, more pickbranchifexsists. possible?


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -