Package net.sf.basedb.util.json
Class JsonUtil
java.lang.Object
net.sf.basedb.util.json.JsonUtil
Utility functions for working with JSON data.
- Since:
- 3.3
- Author:
- nicklas
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> org.json.simple.JSONArray
toArray
(Collection<T> objects, JsonConverter<? super T> converter) Convert a collection of objects to an array with JSON-compatible objects.static <T> org.json.simple.JSONArray
toArray
(Iterator<T> it, JsonConverter<? super T> converter) Convert all objects returned by the iterator to an array with JSON-compatible objects.
-
Constructor Details
-
JsonUtil
public JsonUtil()
-
-
Method Details
-
toArray
public static <T> org.json.simple.JSONArray toArray(Collection<T> objects, JsonConverter<? super T> converter) Convert a collection of objects to an array with JSON-compatible objects. The converter may be null if the objects in the collection are already JSON-compatible.- Parameters:
objects
- The collection of objects to convert and place in the arrayconverter
- An optional converter if needed- Returns:
- A JSON array with the converted objects, if the collection is null or empty an empty array is returned
-
toArray
public static <T> org.json.simple.JSONArray toArray(Iterator<T> it, JsonConverter<? super T> converter) Convert all objects returned by the iterator to an array with JSON-compatible objects. The converter may be null if the objects in the collection are already JSON-compatible.- Parameters:
it
- An iterator returning the objects to convert and place in the arrayconverter
- An optional converter if needed- Returns:
- A JSON array with the converted objects, if the iterator is null or empty an empty array is returned
-