How to return http status code 409 (conflict) along with JSON response from spring REST API, when duplicate email is used during user registration? -


so far have tried following solutions, 1. using response object, don't wish use servlet api of jsp. 2. tried folliwing solution gives html response status code want json instead of html, here relevant code snippet. fetching user email supplied ui

final user user = userdao.findbyemail(email); if (user != null) { throw new duplicaterequestexception(); } 

here exception class:

@produces(mediatype.application_json_value) @responsebody @responsestatus(value = httpstatus.conflict, reason = "email in use") public class duplicaterequestexception extends runtimeexception { } 

i using @restcontroller in spring mvc application, getting desired status code , message response in html format, how can json response status code instead? thanks.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -