{"id":1113,"date":"2023-01-04T18:40:44","date_gmt":"2023-01-04T09:40:44","guid":{"rendered":"https:\/\/java.ihavenomoney.co.kr\/?page_id=1113"},"modified":"2023-01-04T18:40:45","modified_gmt":"2023-01-04T09:40:45","slug":"json-model-to-xml","status":"publish","type":"page","link":"https:\/\/java.ihavenomoney.co.kr\/?page_id=1113","title":{"rendered":"Json Model to XML"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview :  \uc800\uc7a5\ub41c \ubaa8\ub378 \uad6c\uc870\uc5d0\uc11c XML \ub85c \ubcc0\ud658<\/h2>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><\/div>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:java decode:true \" >package com.example.demo;\n\nimport com.fasterxml.jackson.databind.SerializationFeature;\nimport com.fasterxml.jackson.dataformat.xml.XmlMapper;\nimport com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;\nimport com.google.gson.Gson;\nimport com.google.gson.GsonBuilder;\nimport org.apache.catalina.LifecycleException;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport vo.ScheAirFarRs.ScheAirFarRsVo;\nimport java.io.*;\n\n@SpringBootApplication\npublic class DemoApplication {\n\n    public static void main(String[] args) throws IOException, LifecycleException {\n\n        \/\/SpringApplication.run(DemoApplication.class, args);\n        DemoApplication demo = new DemoApplication();\n\n        GsonBuilder gsonBuilder = new GsonBuilder();\n        gsonBuilder.serializeNulls();\n        Gson gson = gsonBuilder.create();\n\n        try {\n            Reader reader = new FileReader(\"Res002.json\");\n            ScheAirFarRsVo scheAirFarRs =gson.fromJson(reader, ScheAirFarRsVo.class);\n\n            XmlMapper xmlMapper = new XmlMapper();\n\n            xmlMapper.configure(SerializationFeature.INDENT_OUTPUT, true);\n            xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);\n            xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_1_1, true);\n            \/\/xmlMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);\n            StringWriter sw = new StringWriter();\n            xmlMapper.writeValue(sw, scheAirFarRs);\n            System.out.println(sw.toString());\n\n            } catch (Exception e) {\n\n                throw new RuntimeException(\"Unexpected error during parsing body param.\", e);\n            }\n\n    }\n\n}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Overview : \uc800\uc7a5\ub41c \ubaa8\ub378 \uad6c\uc870\uc5d0\uc11c XML \ub85c \ubcc0\ud658<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1113","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/pages\/1113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1113"}],"version-history":[{"count":1,"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/pages\/1113\/revisions"}],"predecessor-version":[{"id":1114,"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/pages\/1113\/revisions\/1114"}],"wp:attachment":[{"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}