java - Proper way to parse the body of an error with Spring's RestTemplate -


i'm using @valid annotation on @requestbody argument uses hibernate validation, ensure it's validated:

public responseentity<?> register(@requestbody @valid registrationmodel registration) { ... 

following recommendations of spring rest book, i'm catching exception , turning nice json error message looks this:

{   "title": "validation failed",   "status": 400,   "detail": "input validation failed",   "timestamp": 1505345551757,   "developermessage": "org.springframework.web.bind.methodargumentnotvalidexception",   "errors": {     "hashedpassword": [       {         "code": "notnull",         "message": "must not null"       }     ],     "organization": [       {         "code": "notblank",         "message": "must not blank"       }     ],     "name": [       {         "code": "notblank",         "message": "must not blank"       }     ]   } } 

on client side, i'm doing make call:

object result = resttemplate.postforobject("http://localhost:8080/v1/registration", registration, object.class); 

using object until define on representation of response. when there's validation error though, 400 error throws httpclienterrorexception.

httpclienterrorexception has getresponsebodyasstring() responds json pasted above. manually parse it, wondering what's correct way parse it. resttemplate has mechanism automatically parsing responses when there's no errors. have errors?


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -