From 80453ca7bad5fdce7eeb8d0143f503051140ad49 Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Tue, 28 Nov 2023 13:28:29 +0900 Subject: [PATCH] =?UTF-8?q?xmlView=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/foundation/boot/MvcConfig.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/cokr/xit/foundation/boot/MvcConfig.java b/src/main/java/cokr/xit/foundation/boot/MvcConfig.java index 99d2da6..3182add 100644 --- a/src/main/java/cokr/xit/foundation/boot/MvcConfig.java +++ b/src/main/java/cokr/xit/foundation/boot/MvcConfig.java @@ -16,8 +16,11 @@ import org.springframework.web.servlet.view.BeanNameViewResolver; import org.springframework.web.servlet.view.JstlView; import org.springframework.web.servlet.view.UrlBasedViewResolver; import org.springframework.web.servlet.view.json.MappingJackson2JsonView; +import org.springframework.web.servlet.view.xml.MappingJackson2XmlView; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; import cokr.xit.foundation.web.AccessInitializer; @@ -96,11 +99,25 @@ public class MvcConfig implements WebMvcConfigurer { @Bean public MappingJackson2JsonView jsonView() { MappingJackson2JsonView bean = new MappingJackson2JsonView(); - bean.setContentType("application/json;charset=UTF-8"); + bean.setContentType("application/json; charset=UTF-8"); bean.setObjectMapper(objectMapper); return bean; } + /**MappingJackson2XmlView를 반환한다. + * @return MappingJackson2XmlView + */ + @Bean + public MappingJackson2XmlView xmlView() { + XmlMapper xmlMapper = new XmlMapper(); + xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true); + + MappingJackson2XmlView bean = new MappingJackson2XmlView(); + bean.setContentType("application/xml; charset=UTF-8"); + bean.setObjectMapper(xmlMapper); + return bean; + } + /**CommonsMultipartResolver를 반환한다. * @return CommonsMultipartResolver */