Class JsonUtil

java.lang.Object
net.sf.basedb.util.json.JsonUtil

public class JsonUtil extends Object
Utility functions for working with JSON data.
Since:
3.3
Author:
nicklas
  • 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 array
      converter - 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 array
      converter - 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