|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.hpi.fgis.dude.util.AbstractIterator<T> de.hpi.fgis.dude.util.data.json.DuDeJsonParser<T>
T
- The type that is used for instantiating during the iteration process.public class DuDeJsonParser<T extends Jsonable>
DuDeJsonParser
can be used for converting a String containing Json syntax into its Java representation. Besides providing methods for
reading the data it also implements the Iterator
interface. The iterating functionality can be used for parsing the content of a
JsonArray
. DuDeJsonParser
can be used for converting a Json String into its Java representation. Besides providing methods for
reading the data it also implements the Iterator
interface. The iterating functionality can be used for parsing the content of a
JsonArray
.
Field Summary | |
---|---|
protected Class<T> |
internalType
is needed for creating new instances (@see Jsonable#fromJson(DuDeJsonParser)) |
Constructor Summary | |
---|---|
protected |
DuDeJsonParser(Class<T> type)
Internal constructor for sub classing. |
|
DuDeJsonParser(Class<T> type,
InputStream stream)
Initializes a new DuDeJsonParser using the passed InputStream . |
|
DuDeJsonParser(Class<T> type,
Reader reader)
Initializes a new DuDeJsonParser using the passed Reader . |
|
DuDeJsonParser(Class<T> type,
String str)
Initializes a new DuDeJsonParser that parses the passed String . |
|
DuDeJsonParser(InputStream stream)
Initializes a new DuDeJsonParser using the passed InputStream . |
|
DuDeJsonParser(Reader reader)
Initializes a new DuDeJsonParser using the passed Reader . |
|
DuDeJsonParser(String str)
Initializes a new DuDeJsonParser that parses the passed String . |
Method Summary | ||
---|---|---|
void |
close()
Closes the used reader. |
|
void |
consolidatePushBack()
Cleans up helper structures used with createPushBackGenerator() .This method should especially be invoked when all pushed json elements have been read. Without calling this method, a slight performance decrease should be observable. |
|
protected org.codehaus.jackson.JsonParseException |
createJsonParseException(String msg)
Creates a new JsonParseException . |
|
protected org.codehaus.jackson.JsonParseException |
createJsonParseException(String msg,
Throwable cause)
Creates a new JsonParseException . |
|
DuDeJsonGenerator |
createPushBackGenerator()
Creates a push back generator for the parser similar to PushbackInputStream .The returned DuDeJsonGenerator might be used to generate arbitrary json elements in front of the current parser position in a FIFO
manner.In order to adjust the internal state to the newly generated json elements, a closing the returned generator with DuDeJsonGenerator.close() is necessary. |
|
String |
currentFieldName()
Returns the current field name without setting the cursor to the next token. |
|
org.codehaus.jackson.JsonToken |
currentToken()
Returns the current token that was loaded during the last nextToken() call. |
|
protected String |
currentTokenName()
Returns the type name of the current token. |
|
boolean |
endOfContentReached()
Checks whether the end of the content was reached. |
|
boolean |
endTokenReached()
Checks whether the current token declares the end of a complex Json structure. |
|
protected void |
finalize()
Closes all streams if it is not already done. |
|
static JsonValue |
getScalarValue(String jsonCode)
Converts the passed String into the corresponding atomic JsonValue . |
|
protected boolean |
hasCurrentToken()
Checks whether a token is loaded. |
|
protected T |
loadNextElement()
Returns the element of the next iteration step. |
|
boolean |
nextBoolean()
Returns the current boolean value. |
|
String |
nextFieldName()
Returns the current field name. |
|
|
nextJsonable(Class<ReturnType> returnType)
Returns the next Json instance. |
|
JsonArray |
nextJsonArray()
Returns the next JsonArray . |
|
JsonBoolean |
nextJsonBoolean()
Returns the next JsonBoolean . |
|
JsonNull |
nextJsonNull()
Returns the next JsonNull . |
|
JsonNumber |
nextJsonNumber()
Returns the next JsonNumber . |
|
JsonRecord |
nextJsonRecord()
Returns the next JsonRecord . |
|
JsonString |
nextJsonString()
Returns the next JsonString . |
|
JsonValue |
nextJsonValue()
Returns any JsonValue . |
|
|
nextObject(Class<C> clazz)
Returns the next instance of the given type initialized with the current json. |
|
String |
nextString()
Returns the current textual value. |
|
protected void |
nextToken()
Loads the next token from the stream. |
|
void |
skipFieldName(String fieldName)
Safely skips the current token if it is a field name with the specified value. |
|
void |
skipToken()
Skips the current token. |
|
void |
skipToken(org.codehaus.jackson.JsonToken expectedType)
Safely skips the current token if it is of the given type. |
Methods inherited from class de.hpi.fgis.dude.util.AbstractIterator |
---|
hasNext, next, remove |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Class<T extends Jsonable> internalType
Constructor Detail |
---|
protected DuDeJsonParser(Class<T> type)
type
- The type that is generated during the iteration process. JsonValue
instances are returned, if null
is passed.public DuDeJsonParser(Class<T> type, InputStream stream) throws org.codehaus.jackson.JsonParseException, IOException
DuDeJsonParser
using the passed InputStream
.
type
- The type that is generated during the iteration process. JsonValue
instances are returned, if null
is passed.stream
- The stream whose data will be parsed.
org.codehaus.jackson.JsonParseException
- If an error occurred while parsing the data.
IOException
- If an error occurred while reading from the stream.public DuDeJsonParser(Class<T> type, Reader reader) throws org.codehaus.jackson.JsonParseException, IOException
DuDeJsonParser
using the passed Reader
.
type
- The type that is generated during the iteration process. JsonValue
instances are returned, if null
is passed.reader
- The reader that is used for parsing the data.
org.codehaus.jackson.JsonParseException
- If an error occurred while parsing the data.
IOException
- If an error occurred while reading from the stream.public DuDeJsonParser(Class<T> type, String str) throws org.codehaus.jackson.JsonParseException, IOException
DuDeJsonParser
that parses the passed String
.
type
- The type that is generated during the iteration process. JsonValue
instances are returned, if null
is passed.str
- The code that shall be parsed.
org.codehaus.jackson.JsonParseException
- If an error occurred while parsing the data.
IOException
- If an error occurred while reading from the stream.public DuDeJsonParser(InputStream stream) throws org.codehaus.jackson.JsonParseException, IOException
DuDeJsonParser
using the passed InputStream
.
stream
- The stream whose data will be parsed.
org.codehaus.jackson.JsonParseException
- If an error occurred while parsing the data.
IOException
- If an error occurred while reading from the stream.public DuDeJsonParser(Reader reader) throws org.codehaus.jackson.JsonParseException, IOException
DuDeJsonParser
using the passed Reader
.
reader
- The reader that is used for parsing the data.
org.codehaus.jackson.JsonParseException
- If an error occurred while parsing the data.
IOException
- If an error occurred while reading from the stream.public DuDeJsonParser(String str) throws org.codehaus.jackson.JsonParseException, IOException
DuDeJsonParser
that parses the passed String
.
str
- The code that shall be parsed.
org.codehaus.jackson.JsonParseException
- If an error occurred while parsing the data.
IOException
- If an error occurred while reading from the stream.Method Detail |
---|
public static JsonValue getScalarValue(String jsonCode)
JsonValue
.
jsonCode
- The String that will be converted.
JsonValue
.public void close() throws IOException
close
in interface Closeable
IOException
Closeable.close()
public void consolidatePushBack()
createPushBackGenerator()
.
protected org.codehaus.jackson.JsonParseException createJsonParseException(String msg)
JsonParseException
.
msg
- The error message.
JsonParseException
instance.protected org.codehaus.jackson.JsonParseException createJsonParseException(String msg, Throwable cause)
JsonParseException
.
msg
- The error message.cause
- The cause of this exception.
JsonParseException
instance.public DuDeJsonGenerator createPushBackGenerator()
PushbackInputStream
.DuDeJsonGenerator
might be used to generate arbitrary json elements in front of the current parser position in a FIFO
manner.DuDeJsonGenerator.close()
is necessary.
public String currentFieldName() throws org.codehaus.jackson.JsonParseException, IOException
org.codehaus.jackson.JsonParseException
- If an error occurs while parsing the Json.
IOException
- If an error occurs while reading the Json.public org.codehaus.jackson.JsonToken currentToken() throws EOFException
nextToken()
call.
EOFException
- If the end of the content was already reached.protected String currentTokenName()
public boolean endOfContentReached()
true
, if #readNextCharacter()
will return null
; otherwise false
.public boolean endTokenReached() throws EOFException
true
, if the end of an array or a record is reached; otherwise false
.
EOFException
- If the stream's end was reached.protected void finalize() throws Throwable
finalize
in class Object
Throwable
protected boolean hasCurrentToken()
true
, if currentToken()
would return the current token; false
, if the end of the content was already
reached.protected T loadNextElement()
AbstractIterator
loadNextElement
in class AbstractIterator<T extends Jsonable>
public boolean nextBoolean() throws org.codehaus.jackson.JsonParseException, IOException
org.codehaus.jackson.JsonParseException
- If an error occurs while parsing the Json.
IOException
- If an error occurs while reading the Json.public String nextFieldName() throws org.codehaus.jackson.JsonParseException, IOException
org.codehaus.jackson.JsonParseException
- If an error occurs while parsing the Json.
IOException
- If an error occurs while reading the Json.public <ReturnType extends Jsonable> ReturnType nextJsonable(Class<ReturnType> returnType) throws org.codehaus.jackson.JsonParseException, IOException
ReturnType
- The type that shall be returned.returnType
- The type that shall be returned.
org.codehaus.jackson.JsonParseException
- If an error occurred while parsing the data.
IOException
- If an error occurred while reading the data.
InstantiationException
- If an error occurred while instantiating the new object.
IllegalAccessException
- If an access error occurred while instantiating the new object.public JsonArray nextJsonArray() throws org.codehaus.jackson.JsonParseException, IOException
JsonArray
. The syntax of the JsonArray
has to start directly. Any leading whitespaces or similar
characters will cause a ParseException.
JsonArray
.
org.codehaus.jackson.JsonParseException
- If the read JsonArray
is invalid in terms of the Json syntax or some leading whitespaces are read.
IOException
- If an error occurs during the reading process.public JsonBoolean nextJsonBoolean() throws org.codehaus.jackson.JsonParseException, IOException
JsonBoolean
. The syntax of the JsonBoolean
has to start directly. Any leading whitespaces or similar
characters will cause a ParseException.
JsonBoolean
.
org.codehaus.jackson.JsonParseException
- If the read JsonBoolean
is invalid in terms of the Json syntax or some leading whitespaces are read.
IOException
- If an error occurs during the reading process.public JsonNull nextJsonNull() throws org.codehaus.jackson.JsonParseException, IOException
JsonNull
. The syntax of the JsonNull
has to start directly. Any leading whitespaces or similar
characters will cause a ParseException.
JsonNull
.
org.codehaus.jackson.JsonParseException
- If the read JsonNull
is invalid in terms of the Json syntax or some leading whitespaces are read.
IOException
- If an error occurs during the reading process.public JsonNumber nextJsonNumber() throws org.codehaus.jackson.JsonParseException, IOException
JsonNumber
. The syntax of the JsonNumber
has to start directly. Any leading whitespaces or similar
characters will cause a ParseException. The passed number will be converted into one of the following types: Integer, Long, or BigDecimal;
Float or Double. The "smallest" data type will be preferred (e.g.: 10000 is converted into a JsonNumber
JsonNumber
.
org.codehaus.jackson.JsonParseException
- If the read JsonNumber
is invalid in terms of the Json syntax or some leading whitespaces are read.
IOException
- If an error occurs during the reading process.public JsonRecord nextJsonRecord() throws org.codehaus.jackson.JsonParseException, IOException
JsonRecord
. The syntax of the JsonRecord
has to start directly. Any leading whitespaces or similar
characters will cause a ParseException.
JsonRecord
.
org.codehaus.jackson.JsonParseException
- If the read JsonRecord
is invalid in terms of the Json syntax or some leading whitespaces are read.
IOException
- If an error occurs during the reading process.public JsonString nextJsonString() throws org.codehaus.jackson.JsonParseException, IOException
JsonString
. The syntax of the JsonString
has to start directly. Any leading whitespaces or similar
characters will cause a JsonParseException.
JsonString
.
org.codehaus.jackson.JsonParseException
- If the read JsonString
is invalid in terms of the Json syntax or some leading whitespaces are read.
IOException
- If an error occurs during the reading process.public JsonValue nextJsonValue() throws org.codehaus.jackson.JsonParseException, IOException
JsonValue
. The syntax of the JsonValue
has to start directly. Any leading whitespaces or similar characters
will cause a ParseException.
JsonValue
.
org.codehaus.jackson.JsonParseException
- If the read JsonValue
is invalid in terms of the Json syntax or some leading whitespaces are read.
IOException
- If an error occurs during the reading process.public <C extends AutoJsonable> C nextObject(Class<C> clazz) throws org.codehaus.jackson.JsonParseException, IOException
C
- the type whose instance is being createdclazz
- the type whose instance is being created
org.codehaus.jackson.JsonParseException
- If the read json is invalid or some leading whitespaces are read.
IOException
- If an error occurs during the reading process.public String nextString() throws org.codehaus.jackson.JsonParseException, IOException
org.codehaus.jackson.JsonParseException
- If an error occurs while parsing the Json.
IOException
- If an error occurs while reading the Json.protected void nextToken() throws org.codehaus.jackson.JsonParseException, IOException
org.codehaus.jackson.JsonParseException
- If an error occurred while parsing the data.
IOException
- If an error occurred while reading from the stream.public void skipFieldName(String fieldName) throws org.codehaus.jackson.JsonParseException, IOException
fieldName
- The expected field name
IOException
- If an error occurs while reading the Json.
org.codehaus.jackson.JsonParseException
- If the current token is not the expected field name or an error occurs while parsing the Json.public void skipToken() throws org.codehaus.jackson.JsonParseException, IOException
IOException
- If an error occurs while reading the Json.
org.codehaus.jackson.JsonParseException
- If an error occurs while parsing the Json.public void skipToken(org.codehaus.jackson.JsonToken expectedType) throws org.codehaus.jackson.JsonParseException, IOException
expectedType
- The expected JsonToken
type
IOException
- If an error occurs while reading the Json.
org.codehaus.jackson.JsonParseException
- If the current token is not of the expected type or an error occurs while parsing the Json.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |