org.labkey.remoteapi.internal.ResponseUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of labkey-client-api Show documentation
Show all versions of labkey-client-api Show documentation
The client-side library for Java developers is a separate JAR from the LabKey Server code base. It can be used by any Java program, including another Java web application.
package org.labkey.remoteapi.internal;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class ResponseUtils
{
private ResponseUtils()
{
// Static utility class. Do not construct.
}
/**
* Convert JSON Object to map and make a thoroughly unmodifiable copy of that map.
* Any nested {@link JSONObject}s or {@link JSONArray}s will be similarly processed.
* @param jsonObject Map to copy
* @return Unmodifiable copy of the provided JSONObject.
* @see JSONObject#toMap()
*/
public static Map deepUnmodifiableMap(JSONObject jsonObject)
{
if (jsonObject == null)
return null;
return deepUnmodifiableMap(jsonObject.toMap());
}
/**
* Make a thoroughly unmodifiable copy of a Map that was generated by a JSONObject.
* Any nested {@link Map}s or {@link List}s will be made unmodifiable.
* @param map Map to copy
* @return Unmodifiable copy of the provided Map
* @see JSONObject#toMap()
*/
public static Map deepUnmodifiableMap(Map map)
{
if (map == null)
return null;
Map mapCopy = new LinkedHashMap<>(map.size());
for (String key : map.keySet())
{
mapCopy.put(key, processValueForDeepCopy(map.get(key)));
}
return Collections.unmodifiableMap(mapCopy);
}
/**
* Make a thoroughly unmodifiable copy of a List that was generated by a JSONArray.
* Any nested {@link Map}s or {@link List}s will also be made unmodifiable.
* @param list List to copy
* @return Unmodifiable copy of the provided Map
* @see JSONArray#toList()
*/
public static List