Spring-boot return json and xml from controllers

前端 未结 8 1521
Happy的楠姐
Happy的楠姐 2020-12-16 12:05

I have a spring-boot 1.1.7 application that uses Thymeleaf for much of the UI, so the response from my controllers hasn\'t really been a concern. However, now I need to pro

8条回答
  •  难免孤独
    2020-12-16 12:38

    In addition to what Michael told in his answer, I added the following dependencies as well to pom.xml

    
        org.codehaus.woodstox
        woodstox-core-asl
        4.4.1
    
    

    For some reason, the jackson-dataformat-xml alone was not helping. I also made sure that ResponseEntity is returned in the get call and removed the produces=MediaType from the RequestMapping annotation.

    With these changes, I was able to get the correct data but I had to give the extension of mime type to the REST URL during get call. ie, specify explicitly like: http://localhost:8080/hello.xml or http://localhost:8080/hello.json in browser

提交回复
热议问题