Spring Boot REST with XML Support

前端 未结 2 1590
难免孤独
难免孤独 2021-01-18 00:39

I made a simple REST webservice with Spring Boot 1.2.5 and it works fine for JSON but I can\'t make this work to return XML.

This is my controller:

         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-18 00:48

    To make this work in Spring Boot without using Jersey we need to add this dependency:

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

    The output will be a bit ugly but it works:

    
        
            
            Swimming
            55
            
        
        
            
            Cycling
            120
            
        
    
    

    Here is nice tutorial: http://www.javacodegeeks.com/2015/04/jax-rs-2-x-vs-spring-mvc-returning-an-xml-representation-of-a-list-of-objects.html

提交回复
热议问题