Skip to content

Commit 0195862

Browse files
authored
Migrate labkey-client-api to use a modern JSON library: JSON-java (#141)
1 parent b794944 commit 0195862

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

LDK/test/src/org/labkey/test/tests/external/labModules/LabModulesTest.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import org.apache.commons.lang3.StringUtils;
1919
import org.apache.commons.lang3.tuple.Pair;
2020
import org.apache.poi.ss.usermodel.Sheet;
21-
import org.json.simple.JSONArray;
22-
import org.json.simple.JSONObject;
2321
import org.junit.Assert;
2422
import org.junit.Test;
2523
import org.junit.experimental.categories.Category;
@@ -479,21 +477,21 @@ private void calculatedColumnsTest() throws Exception
479477
assertTrue("Row " + i + " is missing value for column: " + col, row.containsKey(col));
480478

481479
Object serverVal = row.get(col);
482-
//NOTE: the java api uses org.json.simple.JSONArray, which implements List
483-
if (serverVal instanceof List)
480+
481+
//NOTE: the response value can be a List
482+
if (serverVal instanceof List<?> list)
484483
{
485-
List arr = ((List)serverVal);
486-
String value = arr.size() == 0 ? null : StringUtils.trimToNull(StringUtils.join(arr, "\n"));
484+
String value = list.isEmpty() ? null : StringUtils.trimToNull(StringUtils.join(list, "\n"));
487485
assertEquals("Incorrect value for: " + col + " on row: " + i, expectations[idx], value);
488486
}
489487
else if (serverVal instanceof Date)
490488
{
491489
Date d = dateFormat.parse(expectations[idx]);
492490
assertEquals("Incorrect value for: " + col + " on row " + i, d, serverVal);
493491
}
494-
else if (serverVal != null && (serverVal instanceof Integer || serverVal instanceof Double))
492+
else if ((serverVal instanceof Integer || serverVal instanceof Double))
495493
{
496-
Double d = Double.parseDouble(expectations[idx]);
494+
double d = Double.parseDouble(expectations[idx]);
497495
assertEquals("Incorrect value for: " + col + " on row " + i, d, Double.parseDouble(serverVal.toString()), DELTA);
498496
}
499497
else
@@ -1509,17 +1507,16 @@ private void samplesTableTest() throws Exception
15091507
}
15101508
}
15111509

1512-
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
1510+
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
15131511

1514-
private String getColumnLabel(SelectRowsResponse srr, String name) throws org.json.simple.parser.ParseException
1512+
private String getColumnLabel(SelectRowsResponse srr, String name)
15151513
{
1516-
JSONArray columnModel = (JSONArray) srr.getMetaData().get("fields");
1517-
for (Object o : columnModel)
1514+
List<Map<String, Object>> columnModel = (List<Map<String, Object>>) srr.getMetaData().get("fields");
1515+
for (Map<String, Object> column : columnModel)
15181516
{
1519-
JSONObject json = (JSONObject) o;
1520-
if (name.equalsIgnoreCase((String) json.get("name")))
1517+
if (name.equalsIgnoreCase((String) column.get("name")))
15211518
{
1522-
return String.valueOf(json.get("caption"));
1519+
return (String)column.get("caption");
15231520
}
15241521
}
15251522

0 commit comments

Comments
 (0)