java - RESTful: return error code in place of JSON -


i have post method in restful:

@post @produces("application/json") @consumes("application/json") public string dopostjson(string string) {     ... } 

normally gets json , returns json. if face incorrect json in received parameter return error code "400 bad request". how can that?

thanks.

you can throw webapplicationexception code when got incorrect json. might better idea extend webapplicationexception if use exception in other places well.

throw new webapplicationexception(response.status.bad_request); 

you can see more detailed on webapplicationexception here:
http://docs.oracle.com/javaee/6/api/javax/ws/rs/webapplicationexception.html

and list of response.status here:
http://docs.oracle.com/javaee/6/api/javax/ws/rs/core/response.status.html

another read in related this:
jax-rs / jersey how customize error handling?


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -