I have a JSON REST API server built using the Play v2.3 platform with scala, and I have a controller action, for example this:
def register = Action.async(BodyParsers.parse.json) { implicit request => request.body.validate[Register].fold( errors => Future.successful(BadRequest(JsError.toFlatJson(errors))), register => { // do something here if no error... } ) }
For simplicity, I handle the validation error with JsError.toFlatJson (note: JsError.toFlatJson is deprecated in the new Play, replacement is JsError.toJson ).
The problem is that the json result has a cryptic message like:
{"obj.person.email":[{"msg":"error.email","args":[]}]}
Above json indicates that the person's email message is invalid.
Is there a way to convert the result of a json error into a more readable message?
I do not want client applications to perform obj.person.email or error.email mapping / conversion. I prefer the server to do this before json returns to client applications.
source share