2

I am implementing an RESTful Webservice which returns every content formatted as JSON. I am also using Spring OAuth2, but all error messages like invalid access token etc are returned in XML format. How can I return these OAuth2 errors as JSON? By the way, the access tokens are returned as JSON String.

1 Answer 1

5

We have faced the same problem.

After hours and hours of configuring it on server side we have found better way to migrate this nuisance.

Error messages for OAuth2 for Spring defaults to xml but with one simple trick you can change them to JSON: by sending Accept: application/json in request headers.

Hope I helped a bit.

2
  • @BigDong in our Angular app Sep 15, 2016 at 22:17
  • You just save my life man!!! I'm testing my server using Postman and I just add this to the header... The response changed to JSON.
    – Magno C
    May 25, 2018 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.