phoenix
phoenix

Reputation: 995

Convert an XML file to Json using using Gson

I found that many of the tutorials on the net and here on SO also refer to net.sf.json library to convert an xml file to json object.

But, I want an alternative preferably using Gson. Is it possible? I don't have well defined Java Classes for the XML file. But, I just want to convert the xml file to com.google.gson.JsonObject. How to achieve it?

Upvotes: 5

Views: 26473

Answers (1)

Michallis
Michallis

Reputation: 52

I've done the same using JAXB to convert my xml to an object, and passing the object to gson. I know it takes one additional step, but that worked convenient for me. Upon converting xml to jaxb see also: Use JAXB to create Object from XML String

Upvotes: 2

Related Questions