Spring-boot return json and xml from controllers

前端 未结 8 1491
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:41

    I had the exact same problem and I found the solution on Spring documentation website : here

    In synthesis, I added the following dependency to the pom.xml of my project :

    
         com.fasterxml.jackson.dataformat
         jackson-dataformat-xml
     
    

    Then I added the following code block to the class that the service had to return :

     import javax.xml.bind.annotation.XmlRootElement;
    
     @XmlRootElement
     public class Greeting {...}
    

    And it worked.

提交回复
热议问题