net.minidev.json
Class JSONNavi<T>

java.lang.Object
  extended by net.minidev.json.JSONNavi<T>

public class JSONNavi<T>
extends Object

A JQuery like Json editor, accessor.

Since:
1.0.9
Author:
Uriel Chemouni

Constructor Summary
JSONNavi(AMapper<? super T> mapper)
           
JSONNavi(String json)
           
JSONNavi(String json, AMapper<T> mapper)
           
JSONNavi(String json, Class<T> mapTo)
           
 
Method Summary
 JSONNavi<T> add(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
 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
 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
 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
 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
 Long asLongObj()
          get the current object value as Long if the current Object can not be cast as Long return null.
 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(String key)
           
 JSONNavi<?> atNext()
          Access to last + 1 the index position.
 Object getCurrentObject()
           
 String getJPath()
           
 T getRoot()
           
 boolean hasFailure()
           
static JSONNavi<JSONAwareEx> newInstance()
           
static JSONNavi<JSONArray> newInstanceArray()
           
static JSONNavi<JSONObject> newInstanceObject()
           
 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(Boolean bool)
          set current value as Boolean
 JSONNavi<T> set(Number num)
          set current value as Number
 JSONNavi<T> set(String text)
          set current value as String
 JSONNavi<T> set(String key, double value)
          write an value in the current object
 JSONNavi<T> set(String key, float value)
          write an value in the current object
 JSONNavi<T> set(String key, int value)
          write an value in the current object
 JSONNavi<T> set(String key, long value)
          write an value in the current object
 JSONNavi<T> set(String key, Number value)
           
 JSONNavi<T> set(String key, String value)
           
 String toString()
          return the Object as a Json String
 String toString(JSONStyle compression)
          return the Object as a Json String
 JSONNavi<?> up()
          Move one level up in Json tree. if no more level up is available the statement had no effect.
 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
 

Constructor Detail

JSONNavi

public JSONNavi(AMapper<? super T> mapper)

JSONNavi

public JSONNavi(String json)

JSONNavi

public JSONNavi(String json,
                AMapper<T> mapper)

JSONNavi

public JSONNavi(String json,
                Class<T> mapTo)
Method Detail

newInstance

public static JSONNavi<JSONAwareEx> newInstance()

newInstanceObject

public static JSONNavi<JSONObject> newInstanceObject()

newInstanceArray

public static JSONNavi<JSONArray> newInstanceArray()

root

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


hasFailure

public boolean hasFailure()

getCurrentObject

public Object getCurrentObject()

at

public JSONNavi<?> at(String key)

set

public JSONNavi<T> set(String key,
                       String value)

set

public JSONNavi<T> set(String key,
                       Number value)

set

public JSONNavi<T> set(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(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(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(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(Object... values)
add value to the current arrays

Parameters:
values - to add
Returns:
this

asString

public 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 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 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 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 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 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(Number num)
set current value as Number


set

public JSONNavi<T> set(Boolean bool)
set current value as Boolean


set

public JSONNavi<T> set(String text)
set current value as String


getRoot

public T getRoot()

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 String toString()
return the Object as a Json String

Overrides:
toString in class Object

toString

public String toString(JSONStyle compression)
return the Object as a Json String

Parameters:
compression -

getJPath

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


Copyright © 2012 Chemouni Uriel. All Rights Reserved.