How to convert an xml into a json using gson library

Tags: , , ,

I have to convert a XML using gson library into a JSON

i haven´t found how to do it using gson library(java)


You could use Jackson to do this:

import these libraries:


then do this in your class:

    public class Example {
        private String name;
        private int number;
    Example example = new XmlMapper().readValue(xml, Example.class);
    String json = new ObjectMapper().writeValueAsString(example);

Source: stackoverflow