Class JSONValue

  • Direct Known Subclasses:
    JSONComplex, JSONSimple

    public abstract class JSONValue
    extends java.lang.Object
    Base class for all JSON representations.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int col  
      private java.lang.Object data  
      private int line  
      private java.lang.String streamName  
    • Constructor Summary

      Constructors 
      Constructor Description
      JSONValue()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static JSONValue decorate​(java.lang.Object anObject)
      This method is the reverse of a strip, it converts a construction of Java objects to a JSON decorated composition.
      int getCol()
      Get the column number in the textual representation where this JSON value was encountered.
      java.lang.Object getData()
      Get user data.
      int getLine()
      Get the line number in the textual representation where this JSON value was encountered.
      java.lang.String getStreamName()
      Get information about the stream in which the value occurred.
      boolean isArray()
      Check if this value represents an array.
      boolean isBoolean()
      Check if this value represents a JSON boolean value.
      boolean isComplex()
      Check if this value represents a "complex" value, meaning: an array, an object.
      boolean isDecimal()
      Check if this value is a decimal.
      boolean isInteger()
      Check if this value is an integer.
      boolean isNull()
      Check if this value represents a JSON null value.
      boolean isNumber()
      Check if this value is a number, meaning: an integer or a decimal.
      boolean isObject()
      Check if this value represents a JSON object.
      boolean isSimple()
      Check if this value represents a "simple" value, meaning: a boolean, a number, a string or null.
      boolean isString()
      Check if this value represents a JSON string.
      java.lang.String render​(boolean pretty)
      Convert the JSON value into a string representation (JSON representation).
      protected abstract java.lang.String render​(boolean pretty, java.lang.String indent)
      Convert the JSON value into a string representation (JSON representation).
      void setData​(java.lang.Object data)
      Set user data.
      void setLineCol​(int line, int col)
      Set The position where this JSON value occurred during parsing.
      void setStreamName​(java.lang.String streamName)
      Fill in information about the stream.
      abstract java.lang.Object strip()
      This method strips all JSON related information and returns pure Java objects.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • streamName

        private java.lang.String streamName
      • line

        private int line
      • col

        private int col
      • data

        private java.lang.Object data
    • Constructor Detail

      • JSONValue

        public JSONValue()
    • Method Detail

      • getLine

        public int getLine()
        Get the line number in the textual representation where this JSON value was encountered. Can be handy for post processing tools which want to give an indication tot he user where in the representation some condition occurred.
        Returns:
        The line number.
      • setLineCol

        public void setLineCol​(int line,
                               int col)
        Set The position where this JSON value occurred during parsing. This method is called by the parser. Probably no need to call this yourself.
        Parameters:
        line -
        col -
      • getStreamName

        public java.lang.String getStreamName()
        Get information about the stream in which the value occurred. Its purpose is to identify in which stream the error occurred if multiple streams are being parsed and the error reports are being collected in a single report.
        Returns:
        The name of the stream.
      • setStreamName

        public void setStreamName​(java.lang.String streamName)
        Fill in information about the stream.
        Parameters:
        streamName -
      • getCol

        public int getCol()
        Get the column number in the textual representation where this JSON value was encountered. Can be handy for post processing tools which want to give an indication tot he user where in the representation some condition occurred.
        Returns:
        The line number.
      • getData

        public java.lang.Object getData()
        Get user data.
        Returns:
        The user data.
      • setData

        public void setData​(java.lang.Object data)
        Set user data. The user of the library can link whatever information is useful in the user context to a JSON object in order to track back to the original JSON data. The JSON tools do not use this field, it is for the user of the library.
        Parameters:
        data -
      • isSimple

        public boolean isSimple()
        Check if this value represents a "simple" value, meaning: a boolean, a number, a string or null.
        Returns:
        An assertion that the value is "simple".
      • isComplex

        public boolean isComplex()
        Check if this value represents a "complex" value, meaning: an array, an object.
        Returns:
        An assertion that the value is "complex".
      • isArray

        public boolean isArray()
        Check if this value represents an array.
        Returns:
        An assertion that the value is an array.
      • isObject

        public boolean isObject()
        Check if this value represents a JSON object.
        Returns:
        An assertion that the value is a JSON object.
      • isNumber

        public boolean isNumber()
        Check if this value is a number, meaning: an integer or a decimal.
        Returns:
        An assertion that the value is a number.
      • isDecimal

        public boolean isDecimal()
        Check if this value is a decimal.
        Returns:
        An assertion that the value is a decimal.
      • isInteger

        public boolean isInteger()
        Check if this value is an integer.
        Returns:
        An assertion that the value is an integer.
      • isNull

        public boolean isNull()
        Check if this value represents a JSON null value.
        Returns:
        An assertion that the value is the JSON null value.
      • isBoolean

        public boolean isBoolean()
        Check if this value represents a JSON boolean value.
        Returns:
        An assertion that the value is a JSON boolean.
      • isString

        public boolean isString()
        Check if this value represents a JSON string.
        Returns:
        An assertion that the value is a JSON string.
      • render

        public java.lang.String render​(boolean pretty)
        Convert the JSON value into a string representation (JSON representation).
        Parameters:
        pretty - Indicating if the print should be made pretty (human readers) or compact (transmission or storage).
        Returns:
        A JSON representation.
      • render

        protected abstract java.lang.String render​(boolean pretty,
                                                   java.lang.String indent)
        Convert the JSON value into a string representation (JSON representation).
        Parameters:
        pretty - Indicating if the print should be made pretty (human readers) or compact (transmission or storage).
        indent - Starting indent.
        Returns:
        A JSON representation.
      • strip

        public abstract java.lang.Object strip()
        This method strips all JSON related information and returns pure Java objects. It can be handy if you know in advance which objects to expect or if you already did validation.
        Returns:
        Pure Java object, stripped of all JSON information.
      • decorate

        public static JSONValue decorate​(java.lang.Object anObject)
        This method is the reverse of a strip, it converts a construction of Java objects to a JSON decorated composition.
        Parameters:
        anObject -
        Returns:
        A JSONValue representing the object.
        Throws:
        java.lang.IllegalArgumentException - If a conversion cannot be done.