Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert an XML file to Json using using Gson

Tags:

java

json

xml

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?

like image 683
phoenix Avatar asked Nov 01 '22 12:11

phoenix


1 Answers

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

like image 191
Michallis Avatar answered Nov 13 '22 14:11

Michallis