Overview : 저장된 모델 구조에서 XML 로 변환
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
package com.example.demo; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import org.apache.catalina.LifecycleException; import org.springframework.boot.autoconfigure.SpringBootApplication; import vo.ScheAirFarRs.ScheAirFarRsVo; import java.io.*; @SpringBootApplication public class DemoApplication { public static void main(String[] args) throws IOException, LifecycleException { //SpringApplication.run(DemoApplication.class, args); DemoApplication demo = new DemoApplication(); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.serializeNulls(); Gson gson = gsonBuilder.create(); try { Reader reader = new FileReader("Res002.json"); ScheAirFarRsVo scheAirFarRs =gson.fromJson(reader, ScheAirFarRsVo.class); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.configure(SerializationFeature.INDENT_OUTPUT, true); xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true); xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_1_1, true); //xmlMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); StringWriter sw = new StringWriter(); xmlMapper.writeValue(sw, scheAirFarRs); System.out.println(sw.toString()); } catch (Exception e) { throw new RuntimeException("Unexpected error during parsing body param.", e); } } } |