0

After adding spring-security module to my Spring app, when I use postman to post a request with Authorization option is No Auth and header Accept is */*, the Spring app returns a xml body like:

<Map>
    <timestamp>1563355321349</timestamp>
    <status>401</status>
    <error>Unauthorized</error>
    <message>Unauthorized</message>
    <path>/odm/test</path>
</Map>

It returns xml when Unauthorize but when the request is successfully authenticated, the body is in json.

I want the Unauthorize response body to be in json instead of xml. I tried to remove MappingJackson2XmlHttpMessageConverter from HttpMessageConverters list and it works but I want to keep it in list of course. Does Spring prioritize xml over json when Accept header is */* ?

Anyway to set Gson as default http message converter instead of Jackson in Spring boot 2.0 ?

Thach Huynh
  • 1,173
  • 2
  • 12
  • 24
  • I added GsonHttpMessageConverter to the first of the list but when I debug into the code, it still use ```AbstractJackson2HttpMessageConverter``` instead of Gson. I config to use only one GsonHttpMessageConverter in the list but it still return xml – Thach Huynh Jul 17 '19 at 11:44
  • You mean the mime type of HttpMessageConverter ? It is GsonHttpMessageConverter so it only support json. – Thach Huynh Jul 17 '19 at 12:05

0 Answers0