Module com.gluonhq.connect
Package com.gluonhq.connect.converter
Class JsonIterableInputConverter<E>
- java.lang.Object
-
- com.gluonhq.connect.converter.InputStreamIterableInputConverter<E>
-
- com.gluonhq.connect.converter.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 ofJsonConverter
.
-
-
Constructor Summary
Constructors Constructor Description 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 specifiedtargetClass
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
Returnstrue
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.Iterator<E>
iterator()
Returns an Iterator that loops over the items in the JSON Array that is read from the InputStream.E
next()
Returns the next element in the iteration.-
Methods inherited from class com.gluonhq.connect.converter.InputStreamIterableInputConverter
getInputStream, setInputStream
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
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 specifiedtargetClass
.The
targetClass
can be any of the types listed below. All other types will be converted from JSON by using aJsonConverter
.- 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.
-
hasNext
public boolean hasNext()
Returnstrue
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.
-
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 thenext()
method is called.- Specified by:
iterator
in interfaceIterableInputConverter<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.
-
-