Package net.minidev.json
Class JSONNavi<T>
- java.lang.Object
-
- net.minidev.json.JSONNavi<T>
-
public class JSONNavi<T> extends java.lang.Object
A JQuery like Json editor, accessor.- Since:
- 1.0.9
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object
current
private static JSONStyle
ERROR_COMPRESS
private boolean
failure
private java.lang.String
failureMessage
private JsonReaderI<? super T>
mapper
private java.lang.Object
missingKey
private java.util.Stack<java.lang.Object>
path
private boolean
readonly
private T
root
private java.util.Stack<java.lang.Object>
stack
-
Constructor Summary
Constructors Constructor Description JSONNavi(java.lang.String json)
JSONNavi(java.lang.String json, java.lang.Class<T> mapTo)
JSONNavi(java.lang.String json, JsonReaderI<T> mapper)
JSONNavi(JsonReaderI<? super T> mapper)
-
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 ListJSONNavi<T>
add(java.lang.Object... values)
add value to the current arraysJSONNavi<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 falsejava.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.NaNjava.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.NaNjava.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 0java.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 0java.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 arrayprivate boolean
isArray(java.lang.Object obj)
check if Object is an Arrayboolean
isObject()
is the current node is an objectprivate boolean
isObject(java.lang.Object obj)
check if Object is an Mapstatic 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 MapJSONNavi<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 nodeJSONNavi<T>
set(java.lang.Boolean bool)
set current value as BooleanJSONNavi<T>
set(java.lang.Number num)
set current value as NumberJSONNavi<T>
set(java.lang.String text)
set current value as StringJSONNavi<T>
set(java.lang.String key, double value)
write an value in the current objectJSONNavi<T>
set(java.lang.String key, float value)
write an value in the current objectJSONNavi<T>
set(java.lang.String key, int value)
write an value in the current objectJSONNavi<T>
set(java.lang.String key, long value)
write an value in the current objectJSONNavi<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 localizationjava.lang.String
toString()
return the Object as a Json Stringjava.lang.String
toString(JSONStyle compression)
return the Object as a Json StringJSONNavi<?>
up()
Move one level up in Json tree.JSONNavi<?>
up(int level)
call up() level times.
-
-
-
Field Detail
-
mapper
private JsonReaderI<? super T> mapper
-
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
-
newInstance
public static JSONNavi<JSONAwareEx> newInstance()
-
newInstanceObject
public static JSONNavi<JSONObject> newInstanceObject()
-
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, long value)
write an value in the current object- Parameters:
key
- key to accessvalue
- 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 accessvalue
- 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 accessvalue
- 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 accessvalue
- 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.
-
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 classjava.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
-
-