티스토리 뷰

728x90

jaxb 사용해서 xml을 http body로 떨구어줄 때

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

해당 태그를 없애는 방법

Jaxb2RootElementHttpMessageConverter의 하위 클래스를 직접 생성하고 마샬러를 사용자 정의한다.

@Configuration
class XmlConfiguration {
    @Bean
    Jaxb2RootElementHttpMessageConverter jaxb2RootElementHttpMessageConverter() {
        return new Jaxb2RootElementHttpMessageConverter() {
            @Override
            @SneakyThrows
            protected void customizeMarshaller(Marshaller marshaller) {
                marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
            }
        };
    }
}

참고

https://stackoverflow.com/questions/18050314/how-to-remove-xml-header-for-spring-mvc-responsebody

 

How to remove XML header for spring mvc @ResponseBody?

@RequestMapping(method = RequestMethod.GET, produces = "application/xml") @ResponseBody resonpse xml like this <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <xml> <co...

stackoverflow.com

 

728x90
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함