Class JsonIterableInputConverter<E>

  • Type Parameters:
    E - the type of the object that the items in the JSON Array are converted into
    All Implemented Interfaces:
    IterableInputConverter<E>, Iterator<E>

    public class JsonIterableInputConverter<E>
    extends InputStreamIterableInputConverter<E>
    implements Iterator<E>
    An IterableInputConverter that converts a JSON Array read from an InputStream into an Iterator that can be used to iterate over a list of objects. The actual conversion from JSON to an object is handled by an instance of JsonConverter.
    • Constructor Detail

      • JsonIterableInputConverter

        public JsonIterableInputConverter​(Class<E> targetClass)
        Construct a new instance of a JsonIterableInputConverter that is able to convert the data read from the InputStream into objects of the specified targetClass.

        The targetClass can be any of the types listed below. All other types will be converted from JSON by using a JsonConverter.

        • java.lang.Boolean: read from the JSON value as JsonValue.TRUE or JsonValue.FALSE
        • java.lang.Byte: read from the JSON value as an int and converted into a byte
        • java.lang.Double: read from the JSON value as a JSON number from which the double value is taken
        • java.lang.Float: read from the JSON value as a JSON number from which the double value is taken that is converted to a float
        • java.lang.Integer: read from the JSON value as an int
        • java.lang.Long: read from the JSON value as a JSON number from which the long value is taken
        • java.lang.Short: read from the JSON value as an int and converted into a short
        • java.lang.String: read from the JSON value as a JSON String
        • javax.json.JsonObject: the returned objects will be the actual JSON Object that is read from the JSON Array
        Parameters:
        targetClass - The class defining the objects being converted from JSON.
    • Method Detail

      • next

        public E next()
        Returns the next element in the iteration. In this case, it will be an object that is converted from the next available element in the JSON Array that was read from the InputStream.
        Specified by:
        next in interface Iterator<E>
        Returns:
        An object converted from the JSON Value that is taken from the next element in the JSON Array.
      • hasNext

        public boolean hasNext()
        Returns true if the iteration has more elements, in this case if there are more elements to be returned from the JSON Array that was read from the InputStream.
        Specified by:
        hasNext in interface Iterator<E>
        Returns:
        true if there are more items available in the Iterator, false otherwise.
      • iterator

        public Iterator<E> iterator()
        Returns an Iterator that loops over the items in the JSON Array that is read from the InputStream. This implementation returns itself as the Iterator. Each element inside the JSON Array will be converted into the correct object when the next() method is called.
        Specified by:
        iterator in interface IterableInputConverter<E>
        Returns:
        An Iterator that can be used to loop over the objects that are contained in the JSON Array that was read from the InputStream.