Skip to content

Commit

Permalink
Merge pull request #440 from tejones/teiiddes-2457-master
Browse files Browse the repository at this point in the history
teiiddes-2457-master
  • Loading branch information
blafond committed Mar 30, 2015
2 parents 93bd830 + 33a8b51 commit 1292877
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.INewWizard;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.XML;
Expand Down Expand Up @@ -715,15 +716,26 @@ private File getXmlFileFromRestUrl(IConnectionProfile profile) {
private File convertJsonToXml(File jsonFile) throws IOException, Exception {

String jsonText = null;
boolean isArray = false;
String xml;
try {
jsonText = readFile(jsonFile);
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
JSONObject jsonObject = new JSONObject(jsonText);
if (jsonText.trim().startsWith("[")) {
isArray = true;
}

if (isArray){
JSONArray jsonArray = new JSONArray(jsonText);
xml = "<response>" + XML.toString(jsonArray, "response") + "</response>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else{
JSONObject jsonObject = new JSONObject(jsonText);
xml = XML.toString(jsonObject, "response"); //$NON-NLS-1$
}

String xml = XML.toString(jsonObject, "result"); //$NON-NLS-1$
FileUtils.write(xml.getBytes(), jsonFile);
return jsonFile;

Expand Down

0 comments on commit 1292877

Please sign in to comment.