-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractStructuredReader
public interface StructuredReader extends AutoCloseable
Interface for a reader to parse astructured format
such as JSON or XML.- Since:
- 1.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
StructuredReader.State
Enum with the possible states of aStructuredReader
.
-
Method Summary
-
-
-
Method Detail
-
readName
String readName()
- Returns:
- the name of the current property or element.
-
readStartObject
boolean readStartObject()
- Returns:
true
if pointing to the start of an object,false
otherwise.- See Also:
StructuredWriter.writeStartObject()
-
readStartArray
boolean readStartArray()
- Returns:
true
if pointing to the start of an object,false
otherwise.- See Also:
StructuredWriter.writeStartArray()
-
readValue
Object readValue()
Generic method to read and unmarshall a value supporting only the build in typesBoolean
,String
, andNumber
.- Returns:
- the unmarsahlled value. May be
null
.
-
readValue
Object readValue(boolean recursive)
-
readObject
void readObject(Map<String,Object> map)
This method may be called if thecurrent state
isStructuredReader.State.START_OBJECT
to read the object into the givenMap
. After the call of this method thestate
will point to thenext
one after the correspondingStructuredReader.State.END_OBJECT
.- Parameters:
map
- theMap
where to add the properties. UnlikereadValue(boolean)
this allows you to choose theMap
implementation.
-
readArray
void readArray(Collection<Object> array)
This method may be called called if thecurrent state
isStructuredReader.State.START_ARRAY
to read the array into the givenCollection
. After the call of this method thestate
will point to thenext
one after the correspondingStructuredReader.State.END_ARRAY
.- Parameters:
array
- theCollection
where to add thevalues
.
-
readValue
default <V> V readValue(Class<V> type)
Generic method to read and unmarshall a value.
ATTENTION:
This generic method only exists as convenience method for thereadValueAs*
methods. It therefore only supports standard Java value types as described inio.github.mmm.marshall
. For other types it will throw anIllegalArgumentException
.- Type Parameters:
V
- type of the value to read.- Parameters:
type
-Class
reflecting the value to read.- Returns:
- the unmarsahlled value. May be
null
.
-
readValueAsString
String readValueAsString()
- Returns:
- reads the value as
String
. - See Also:
readValue(Class)
-
readValueAsBoolean
Boolean readValueAsBoolean()
- Returns:
- reads the value as
Boolean
. - See Also:
readValue(Class)
-
readValueAsInteger
Integer readValueAsInteger()
- Returns:
- reads the value as
Integer
. - See Also:
readValue(Class)
-
readValueAsLong
Long readValueAsLong()
- Returns:
- reads the value as
Long
. - See Also:
readValue(Class)
-
readValueAsDouble
Double readValueAsDouble()
- Returns:
- reads the value as
Double
. - See Also:
readValue(Class)
-
readValueAsFloat
Float readValueAsFloat()
- Returns:
- reads the value as
Float
. - See Also:
readValue(Class)
-
readValueAsShort
Short readValueAsShort()
- Returns:
- reads the value as
Short
. - See Also:
readValue(Class)
-
readValueAsByte
Byte readValueAsByte()
- Returns:
- reads the value as
Byte
. - See Also:
readValue(Class)
-
readValueAsBigInteger
BigInteger readValueAsBigInteger()
- Returns:
- reads the value as
BigInteger
. - See Also:
readValue(Class)
-
readValueAsBigDecimal
BigDecimal readValueAsBigDecimal()
- Returns:
- reads the value as
BigDecimal
. - See Also:
readValue(Class)
-
skipValue
void skipValue()
Skips the current value. Should be called afterreadName()
.- If currently at
start of object
, skip that entire object. - If currently at
start of array
, skip the entire array. - If currently at a
single value
, skip that value.
- If currently at
-
isDone
boolean isDone()
- Returns:
true
if all data has been read and the end of the stream has been reached,false
otherwise.
-
getState
StructuredReader.State getState()
- Returns:
- the current state of this reader.
-
next
StructuredReader.State next()
Proceeds to the nextStructuredReader.State
skipping the current information.- Returns:
- the new
StructuredReader.State
.
-
close
void close()
- Specified by:
close
in interfaceAutoCloseable
-
-