Class JSONNavi<T>


  • public class JSONNavi<T>
    extends java.lang.Object
    A JQuery like Json editor, accessor.
    Since:
    1.0.9
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.util.List<java.lang.Object> a​(java.lang.Object obj)
      internal cast to List
      JSONNavi<T> add​(java.lang.Object... values)
      add value to the current arrays
      JSONNavi<T> array()
      Set current value as Json Array You can also skip this call Arrays can be create automatically.
      boolean asBoolean()
      get the current value as boolean if the current Object is null or is not a boolean return false
      java.lang.Boolean asBooleanObj()
      get the current object value as Boolean if the current Object is not a Boolean return null.
      double asDouble()
      get the current value as double if the current Object is null return Double.NaN
      java.lang.Double asDoubleObj()
      get the current object value as Double if the current Double can not be cast as Integer return null.
      double asFloat()
      get the current value as float if the current Object is null return Float.NaN
      java.lang.Float asFloatObj()
      get the current object value as Float if the current Float can not be cast as Integer return null.
      int asInt()
      get the current value as int if the current Object is null return 0
      java.lang.Integer asIntegerObj()
      get the current object value as Integer if the current Object can not be cast as Integer return null.
      long asLong()
      get the current value as long if the current Object is null return 0
      java.lang.Long asLongObj()
      get the current object value as Long if the current Object can not be cast as Long return null.
      java.lang.String asString()
      get the current object value as String if the current Object is null return null.
      JSONNavi<?> at​(int index)
      Access to the index position.
      JSONNavi<?> at​(java.lang.String key)  
      JSONNavi<?> atNext()
      Access to last + 1 the index position.
      private JSONNavi<?> failure​(java.lang.String err, java.lang.Object jPathPostfix)
      Internally log errors.
      java.lang.Object get​(int index)  
      java.lang.Object get​(java.lang.String key)  
      java.lang.Object getCurrentObject()  
      double getDouble​(java.lang.String key)  
      int getInt​(java.lang.String key)  
      java.lang.Integer getInteger​(java.lang.String key)  
      java.lang.String getJPath()  
      java.util.Collection<java.lang.String> getKeys()  
      T getRoot()  
      int getSize()  
      java.lang.String getString​(java.lang.String key)  
      boolean hasFailure()  
      boolean hasKey​(java.lang.String key)  
      boolean isArray()
      is the current node is an array
      private boolean isArray​(java.lang.Object obj)
      check if Object is an Array
      boolean isObject()
      is the current node is an object
      private boolean isObject​(java.lang.Object obj)
      check if Object is an Map
      static JSONNavi<JSONAwareEx> newInstance()  
      static JSONNavi<JSONArray> newInstanceArray()  
      static JSONNavi<JSONObject> newInstanceObject()  
      private java.util.Map<java.lang.String,​java.lang.Object> o​(java.lang.Object obj)
      internal cast to Map
      JSONNavi<T> object()
      Set current value as Json Object You can also skip this call, Objects can be create automatically.
      JSONNavi<T> root()
      return to root node
      JSONNavi<T> set​(java.lang.Boolean bool)
      set current value as Boolean
      JSONNavi<T> set​(java.lang.Number num)
      set current value as Number
      JSONNavi<T> set​(java.lang.String text)
      set current value as String
      JSONNavi<T> set​(java.lang.String key, double value)
      write an value in the current object
      JSONNavi<T> set​(java.lang.String key, float value)
      write an value in the current object
      JSONNavi<T> set​(java.lang.String key, int value)
      write an value in the current object
      JSONNavi<T> set​(java.lang.String key, long value)
      write an value in the current object
      JSONNavi<T> set​(java.lang.String key, java.lang.Number value)  
      JSONNavi<T> set​(java.lang.String key, java.lang.String value)  
      private void store()
      internal store current Object in current non existing localization
      java.lang.String toString()
      return the Object as a Json String
      java.lang.String toString​(JSONStyle compression)
      return the Object as a Json String
      JSONNavi<?> up()
      Move one level up in Json tree.
      JSONNavi<?> up​(int level)
      call up() level times.
      • Methods inherited from class java.lang.Object

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

      • root

        private T root
      • stack

        private java.util.Stack<java.lang.Object> stack
      • path

        private java.util.Stack<java.lang.Object> path
      • current

        private java.lang.Object current
      • failure

        private boolean failure
      • failureMessage

        private java.lang.String failureMessage
      • readonly

        private boolean readonly
      • missingKey

        private java.lang.Object missingKey
      • ERROR_COMPRESS

        private static final JSONStyle ERROR_COMPRESS
    • Constructor Detail

      • JSONNavi

        public JSONNavi​(JsonReaderI<? super T> mapper)
      • JSONNavi

        public JSONNavi​(java.lang.String json)
      • JSONNavi

        public JSONNavi​(java.lang.String json,
                        JsonReaderI<T> mapper)
      • JSONNavi

        public JSONNavi​(java.lang.String json,
                        java.lang.Class<T> mapTo)
    • Method Detail

      • root

        public JSONNavi<T> root()
        return to root node
      • hasFailure

        public boolean hasFailure()
      • getCurrentObject

        public java.lang.Object getCurrentObject()
      • getKeys

        public java.util.Collection<java.lang.String> getKeys()
      • getSize

        public int getSize()
      • getString

        public java.lang.String getString​(java.lang.String key)
      • getInt

        public int getInt​(java.lang.String key)
      • getInteger

        public java.lang.Integer getInteger​(java.lang.String key)
      • getDouble

        public double getDouble​(java.lang.String key)
      • hasKey

        public boolean hasKey​(java.lang.String key)
      • at

        public JSONNavi<?> at​(java.lang.String key)
      • get

        public java.lang.Object get​(java.lang.String key)
      • get

        public java.lang.Object get​(int index)
      • set

        public JSONNavi<T> set​(java.lang.String key,
                               java.lang.String value)
      • set

        public JSONNavi<T> set​(java.lang.String key,
                               java.lang.Number value)
      • set

        public JSONNavi<T> set​(java.lang.String key,
                               long value)
        write an value in the current object
        Parameters:
        key - key to access
        value - new value
        Returns:
        this
      • set

        public JSONNavi<T> set​(java.lang.String key,
                               int value)
        write an value in the current object
        Parameters:
        key - key to access
        value - new value
        Returns:
        this
      • set

        public JSONNavi<T> set​(java.lang.String key,
                               double value)
        write an value in the current object
        Parameters:
        key - key to access
        value - new value
        Returns:
        this
      • set

        public JSONNavi<T> set​(java.lang.String key,
                               float value)
        write an value in the current object
        Parameters:
        key - key to access
        value - new value
        Returns:
        this
      • add

        public JSONNavi<T> add​(java.lang.Object... values)
        add value to the current arrays
        Parameters:
        values - to add
        Returns:
        this
      • asString

        public java.lang.String asString()
        get the current object value as String if the current Object is null return null.
      • asDouble

        public double asDouble()
        get the current value as double if the current Object is null return Double.NaN
      • asDoubleObj

        public java.lang.Double asDoubleObj()
        get the current object value as Double if the current Double can not be cast as Integer return null.
      • asFloat

        public double asFloat()
        get the current value as float if the current Object is null return Float.NaN
      • asFloatObj

        public java.lang.Float asFloatObj()
        get the current object value as Float if the current Float can not be cast as Integer return null.
      • asInt

        public int asInt()
        get the current value as int if the current Object is null return 0
      • asIntegerObj

        public java.lang.Integer asIntegerObj()
        get the current object value as Integer if the current Object can not be cast as Integer return null.
      • asLong

        public long asLong()
        get the current value as long if the current Object is null return 0
      • asLongObj

        public java.lang.Long asLongObj()
        get the current object value as Long if the current Object can not be cast as Long return null.
      • asBoolean

        public boolean asBoolean()
        get the current value as boolean if the current Object is null or is not a boolean return false
      • asBooleanObj

        public java.lang.Boolean asBooleanObj()
        get the current object value as Boolean if the current Object is not a Boolean return null.
      • object

        public JSONNavi<T> object()
        Set current value as Json Object You can also skip this call, Objects can be create automatically.
      • array

        public JSONNavi<T> array()
        Set current value as Json Array You can also skip this call Arrays can be create automatically.
      • set

        public JSONNavi<T> set​(java.lang.Number num)
        set current value as Number
      • set

        public JSONNavi<T> set​(java.lang.Boolean bool)
        set current value as Boolean
      • set

        public JSONNavi<T> set​(java.lang.String text)
        set current value as String
      • getRoot

        public T getRoot()
      • store

        private void store()
        internal store current Object in current non existing localization
      • isArray

        public boolean isArray()
        is the current node is an array
      • isObject

        public boolean isObject()
        is the current node is an object
      • isArray

        private boolean isArray​(java.lang.Object obj)
        check if Object is an Array
      • isObject

        private boolean isObject​(java.lang.Object obj)
        check if Object is an Map
      • a

        private java.util.List<java.lang.Object> a​(java.lang.Object obj)
        internal cast to List
      • o

        private java.util.Map<java.lang.String,​java.lang.Object> o​(java.lang.Object obj)
        internal cast to Map
      • at

        public JSONNavi<?> at​(int index)
        Access to the index position. If index is less than 0 access element index from the end like in python.
        Parameters:
        index - 0 based desired position in Array
      • atNext

        public JSONNavi<?> atNext()
        Access to last + 1 the index position. this method can only be used in writing mode.
      • up

        public JSONNavi<?> up​(int level)
        call up() level times.
        Parameters:
        level - number of parent move.
      • up

        public JSONNavi<?> up()
        Move one level up in Json tree. if no more level up is available the statement had no effect.
      • toString

        public java.lang.String toString()
        return the Object as a Json String
        Overrides:
        toString in class java.lang.Object
      • toString

        public java.lang.String toString​(JSONStyle compression)
        return the Object as a Json String
        Parameters:
        compression -
      • failure

        private JSONNavi<?> failure​(java.lang.String err,
                                    java.lang.Object jPathPostfix)
        Internally log errors.
      • getJPath

        public java.lang.String getJPath()
        Returns:
        JPath to the current position