0

My application used JAXB. It had all the POJO classes written for Marshalling and unmarshalling of XML. Now we got a new requirement from client to change this XML to YML. Is there a way to convert YML to that XML object of existing pojo classes.

I tried these dependencies:

 <dependencies>
  <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <version>1.21</version>
        </dependency>
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.6.2</version>
</dependency>
  </dependencies>

But they didn't help

Yaml yaml = new Yaml();
            InputStream inputStream = new FileInputStream(boostrapFile);
            System.out.println(inputStream);
            Map<String, Object> map = yaml.load(inputStream);
            System.out.println(map);

            Gson gson = new Gson();
            JsonElement jsonElement = gson.toJsonTree(map);
            Bootstrap pojo = gson.fromJson(jsonElement, Bootstrap.class);
            System.out.println(pojo.getDARCConfig());

Output:null

  • With [this answer](https://stackoverflow.com/a/23774617/9368703) convert your YML to JSON. Once it is converted to JSON it can be easily convert it to XML. Refer [this](https://stackoverflow.com/a/19978281/9368703) – Prasanth Ganesan May 31 '19 at 06:38
  • [YML](https://fdik.org/yml/) already is XML based and it is not the same as [YAML](https://yaml.org/spec/1.2/spec.html) – Anthon May 31 '19 at 07:27

0 Answers0