JSON
Version 1.0

org.codehaus.jackson
Class JsonParser

java.lang.Object
  extended by org.codehaus.jackson.JsonParser
Direct Known Subclasses:
ReaderBasedParserBase

public abstract class JsonParser
extends Object

This is the public API implemented by concrete JSON parser instances.

Author:
Tatu Saloranta

Nested Class Summary
static class JsonParser.NumberType
          Enumeration of possible "native" (optimal) types that can be used for numbers.
 
Constructor Summary
protected JsonParser()
           
 
Method Summary
abstract  void close()
           
abstract  JsonLocation getCurrentLocation()
          Method that returns location of the last processed character; usually for error reporting purposes.
abstract  String getCurrentName()
          Method that can be called to get the name associated with the current event.
abstract  JsonToken getCurrentToken()
           
abstract  BigDecimal getDecimalValue()
           
abstract  double getDoubleValue()
           
abstract  int getIntValue()
          Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java int primitive type.
abstract  long getLongValue()
          Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java long primitive type.
abstract  JsonParser.NumberType getNumberType()
          If current event is of type JsonToken.VALUE_NUMBER_INT or JsonToken.VALUE_NUMBER_FLOAT, returns one of type constants; otherwise returns null.
abstract  Number getNumberValue()
          Generic number value accessor method that will work for all kinds of numeric values.
abstract  JsonReadContext getParsingContext()
          Method that can be used to access current parsing context reader is in.
abstract  String getText()
          Method for accessing textual representation of the current event; if no current event (before first call to nextToken(), or after encountering end-of-input), returns null.
abstract  char[] getTextCharacters()
           
abstract  int getTextLength()
           
abstract  int getTextOffset()
           
abstract  JsonLocation getTokenLocation()
          Method that return the starting location of the current token; that is, position of the first character from input that starts the current token.
abstract  boolean hasCurrentToken()
           
abstract  JsonToken nextToken()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonParser

protected JsonParser()
Method Detail

nextToken

public abstract JsonToken nextToken()
                             throws IOException,
                                    JsonParseException
Returns:
Next token from the stream, if any found, or null to indicate end-of-input
Throws:
IOException
JsonParseException

getCurrentToken

public abstract JsonToken getCurrentToken()
Returns:
Type of the token this parser currently points to, if any: null both before any tokens have been read, and after end-of-input has been encountered.

hasCurrentToken

public abstract boolean hasCurrentToken()

getCurrentName

public abstract String getCurrentName()
                               throws IOException,
                                      JsonParseException
Method that can be called to get the name associated with the current event. Will return null for all token types except for JsonToken.FIELD_NAME.

Throws:
IOException
JsonParseException

close

public abstract void close()
                    throws IOException
Throws:
IOException

getParsingContext

public abstract JsonReadContext getParsingContext()
Method that can be used to access current parsing context reader is in. There are 3 different types: root, array and object contexts, with slightly different available information. Contexts are hierarchically nested, and can be used for example for figuring out part of the input document that correspond to specific array or object (for highlighting purposes, or error reporting). Contexts can also be used for simple xpath-like matching of input, if so desired.


getTokenLocation

public abstract JsonLocation getTokenLocation()
Method that return the starting location of the current token; that is, position of the first character from input that starts the current token.


getCurrentLocation

public abstract JsonLocation getCurrentLocation()
Method that returns location of the last processed character; usually for error reporting purposes.


getText

public abstract String getText()
                        throws IOException,
                               JsonParseException
Method for accessing textual representation of the current event; if no current event (before first call to nextToken(), or after encountering end-of-input), returns null. Method can be called for any event.

Throws:
IOException
JsonParseException

getTextCharacters

public abstract char[] getTextCharacters()
                                  throws IOException,
                                         JsonParseException
Throws:
IOException
JsonParseException

getTextLength

public abstract int getTextLength()
                           throws IOException,
                                  JsonParseException
Throws:
IOException
JsonParseException

getTextOffset

public abstract int getTextOffset()
                           throws IOException,
                                  JsonParseException
Throws:
IOException
JsonParseException

getNumberValue

public abstract Number getNumberValue()
                               throws IOException,
                                      JsonParseException
Generic number value accessor method that will work for all kinds of numeric values. It will return the optimal (simplest/smallest possibl) wrapper object that can express the numeric value just parsed.

Throws:
IOException
JsonParseException

getNumberType

public abstract JsonParser.NumberType getNumberType()
                                             throws IOException,
                                                    JsonParseException
If current event is of type JsonToken.VALUE_NUMBER_INT or JsonToken.VALUE_NUMBER_FLOAT, returns one of type constants; otherwise returns null.

Throws:
IOException
JsonParseException

getIntValue

public abstract int getIntValue()
                         throws IOException,
                                JsonParseException
Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java int primitive type.

Note: if the token is an integer, but its value falls outside of range of Java int, a JsonParseException will be thrown to indicate numeric overflow/underflow.

Throws:
IOException
JsonParseException

getLongValue

public abstract long getLongValue()
                           throws IOException,
                                  JsonParseException
Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java long primitive type.

Note: if the token is an integer, but its value falls outside of range of Java long, a JsonParseException will be thrown to indicate numeric overflow/underflow.

Throws:
IOException
JsonParseException

getDoubleValue

public abstract double getDoubleValue()
                               throws IOException,
                                      JsonParseException
Throws:
IOException
JsonParseException

getDecimalValue

public abstract BigDecimal getDecimalValue()
                                    throws IOException,
                                           JsonParseException
Throws:
IOException
JsonParseException

JSON
Version 1.0

Apache License, Version 2.0