Skip to content

Commit

Permalink
Backport ApiXmlWriter JSON library update - DO NOT MERGE FORWARD (#4642)
Browse files Browse the repository at this point in the history
* Handle new JSONObject type
* Handle new JSONArray type
  • Loading branch information
labkey-martyp authored Aug 2, 2023
1 parent 59f27b7 commit 10bd7a8
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions api/src/org/labkey/api/action/ApiXmlWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,24 @@ else if (value instanceof JSONObject)
{
writeJsonObjInternal((JSONObject) value);
}
// --------------------------------
// DO NOT MERGE THIS FORWARD
else if (value instanceof org.json.JSONObject jo)
{
writeJsonObjInternal(jo);
}
//---------------------------------
else if (value instanceof JSONArray)
{
writeJsonArray((JSONArray) value);
}
// --------------------------------
// DO NOT MERGE THIS FORWARD
else if (value instanceof org.json.JSONArray ja)
{
writeJsonArray(ja);
}
//---------------------------------
else if (value instanceof Map)
{
writeJsonObjInternal(new JSONObject((Map) value));
Expand Down Expand Up @@ -150,6 +164,19 @@ private void writeJsonArray(JSONArray jsonArray) throws XMLStreamException, IOEx
}
}

// --------------------------------
// DO NOT MERGE THIS FORWARD
private void writeJsonArray(org.json.JSONArray jsonArray) throws XMLStreamException, IOException
{
verifyOpen();
for (int i = 0; i < jsonArray.length(); i++)
{
_xmlWriter.writeStartElement(ARRAY_ELEMENT_NAME);
writeObject(jsonArray.get(i));
_xmlWriter.writeEndElement();
}
}
// --------------------------------

@Override
public void close() throws IOException
Expand Down Expand Up @@ -180,6 +207,19 @@ protected void writeJsonObjInternal(JSONObject obj) throws IOException, XMLStrea
}
}

// --------------------------------
// DO NOT MERGE THIS FORWARD
protected void writeJsonObjInternal(org.json.JSONObject json) throws IOException, XMLStreamException
{
verifyOpen();
for (String key : json.keySet())
{
_xmlWriter.writeStartElement(escapeElementName(key));
writeObject(json.get(key));
_xmlWriter.writeEndElement();
}
}
// --------------------------------

@Override
public void startResponse()
Expand Down

0 comments on commit 10bd7a8

Please sign in to comment.