|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.googlecode.fascinator.common.JsonSimple
public class JsonSimple
This class wraps objects and methods of the JSON.simple library.
| Constructor Summary | |
|---|---|
JsonSimple()
Creates an empty JSON object |
|
JsonSimple(File jsonFile)
Creates a JSON object from the specified file |
|
JsonSimple(InputStream jsonIn)
Creates a JSON object from the specified input stream |
|
JsonSimple(JsonObject newJsonObject)
Wrap a JsonObject in this class |
|
JsonSimple(String jsonString)
Creates a JSON object from the specified string |
|
| Method Summary | |
|---|---|
static Map<String,JsonObject> |
fromJavaMap(Map<String,JsonSimple> from)
Take all of the JsonSimple objects in the given Map and return a Map having replace them all with their base JsonObjects. |
org.json.simple.JSONArray |
getArray(Object... path)
Walk down the JSON nodes specified by the path and retrieve the target JSONArray. |
Boolean |
getBoolean(Boolean defaultValue,
Object... path)
Retrieve the Boolean value on the given path. |
Integer |
getInteger(Integer defaultValue,
Object... path)
Retrieve the Integer value on the given path. |
JsonObject |
getJsonObject()
Return the JsonObject holding this object's JSON representation |
List<JsonSimple> |
getJsonSimpleList(Object... path)
Retrieve a list of JsonSimple objects found on the given path. |
Map<String,JsonSimple> |
getJsonSimpleMap(Object... path)
Retrieve a map of JsonSimple objects found on the given path. |
JsonObject |
getObject(Object... path)
Walk down the JSON nodes specified by the path and retrieve the target JsonObject. |
Object |
getPath(Object... path)
Walk down the JSON nodes specified by the path and retrieve the target. |
String |
getString(String defaultValue,
Object... path)
Retrieve the String value on the given path. |
static List<String> |
getStringList(org.json.simple.JSONArray json)
Get a list of strings from the provided JSONArray |
static List<String> |
getStringList(JsonObject json,
String field)
Get a list of strings found on the specified node |
List<String> |
getStringList(Object... path)
Retrieve a list of Strings found on the given path. |
List<Object> |
search(String node)
Search through the JSON for any nodes (at any depth) matching the requested name and return them. |
void |
setPropertySubstitution(boolean newFlag)
Set method for behaviour flag on substituting system properties during string retrieval. |
static List<JsonSimple> |
toJavaList(org.json.simple.JSONArray array)
Take all of the JsonObjects found in a JSONArray, wrap them in JsonSimple objects, then add to a Java list and return. |
static Map<String,JsonSimple> |
toJavaMap(JsonObject object)
Take all of the JsonObjects found in a JsonObject, wrap them in JsonSimple objects, then add to a Java Map and return. |
String |
toString()
Return the String representation of this object's JSON |
String |
toString(boolean pretty)
Return the String representation of this object's JSON, optionally formatted for human readability. |
org.json.simple.JSONArray |
writeArray(Object... path)
Walk down the JSON nodes specified by the path and retrieve the target array, writing each node that doesn't exist along the way. |
JsonObject |
writeObject(Object... path)
Walk down the JSON nodes specified by the path and retrieve the target object, writing each node that doesn't exist along the way. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public JsonSimple()
IOException - if there was an error during creation
public JsonSimple(File jsonFile)
throws IOException
jsonFile - a JSON file
IOException - if there was an error parsing or reading the file
public JsonSimple(InputStream jsonIn)
throws IOException
jsonIn - a JSON stream
IOException - if there was an error parsing or reading the stream
public JsonSimple(String jsonString)
throws IOException
jsonIn - a JSON string
IOException - if there was an error parsing the stringpublic JsonSimple(JsonObject newJsonObject)
newJsonObject - : The JsonObject to wrap| Method Detail |
|---|
public void setPropertySubstitution(boolean newFlag)
Set method for behaviour flag on substituting system properties during string retrieval.
If set to true (default) strings of the form "{$system.property}" will be substituted for matching system properties during retrieval.
newFlag - : The new flag value to set for this behaviourpublic JsonObject getJsonObject()
public org.json.simple.JSONArray getArray(Object... path)
path - : Variable length array of path segments
public JsonObject getObject(Object... path)
path - : Variable length array of path segments
public Object getPath(Object... path)
path - : Variable length array of path segments
public Boolean getBoolean(Boolean defaultValue,
Object... path)
defaultValue - : The fallback value to use if the path is
invalid or not foundpath - : An array of indeterminate length to use as the path
public Integer getInteger(Integer defaultValue,
Object... path)
defaultValue - : The fallback value to use if the path is
invalid or not foundpath - : An array of indeterminate length to use as the path
public String getString(String defaultValue,
Object... path)
defaultValue - : The fallback value to use if the path is
invalid or not foundpath - : An array of indeterminate length to use as the path
public List<String> getStringList(Object... path)
Retrieve a list of Strings found on the given path. Note that this is a utility function, and not designed for data traversal. It will only retrieve Strings found on the provided node, and the node must be a JSONArray.
path - : An array of indeterminate length to use as the path
public List<JsonSimple> getJsonSimpleList(Object... path)
Retrieve a list of JsonSimple objects found on the given path. Note that this is a utility function, and not designed for data traversal. It will only retrieve valid JsonObjects found on the provided node, and wrap them in JsonSimple objects.
Other objects found on that path will be ignored, and if the path itself is not a JSONArray or not found, the function will return NULL.
path - : An array of indeterminate length to use as the path
public Map<String,JsonSimple> getJsonSimpleMap(Object... path)
Retrieve a map of JsonSimple objects found on the given path. Note that this is a utility function, and not designed for data traversal. It will only retrieve valid JsonObjects found on the provided node, and wrap them in JsonSimple objects.
Other objects found on that path will be ignored, and if the path itself is not a JsonObject or not found, the function will return NULL.
path - : An array of indeterminate length to use as the path
public List<Object> search(String node)
Search through the JSON for any nodes (at any depth) matching the requested name and return them. The returned List will be of type Object and require type interrogation for detailed use, but will be implemented as a LinkedList to preserve order.
node - : The node name we are looking for
public org.json.simple.JSONArray writeArray(Object... path)
Walk down the JSON nodes specified by the path and retrieve the target array, writing each node that doesn't exist along the way.
Note, when addressing path segments that are array indices you can use '-1' to indicate that the next object should always be created fresh and appended to the array.
Array indices that are standard (ie. not -1) integers will be read as normal, but return a null value from the method if they are not found. This method will not attempt to write to a non-existing index of an array.
path - : Variable length array of path segments
public JsonObject writeObject(Object... path)
Walk down the JSON nodes specified by the path and retrieve the target object, writing each node that doesn't exist along the way.
Note, when addressing path segments that are array indices you can use '-1' to indicate that the next object should always be created fresh and appended to the array.
Array indices that are standard (ie. not -1) integers will be read as normal, but return a null value from the method if they are not found. This method will not attempt to write to a non-existing index of an array.
path - : Variable length array of path segments
public String toString()
toString in class Objectpublic String toString(boolean pretty)
public static List<String> getStringList(JsonObject json,
String field)
json - object to retrieve fromfield - The field that has the list
public static List<String> getStringList(org.json.simple.JSONArray json)
json - Array to retrieve strings from
public static List<JsonSimple> toJavaList(org.json.simple.JSONArray array)
Take all of the JsonObjects found in a JSONArray, wrap them in JsonSimple objects, then add to a Java list and return.
All entries found that are not JsonObjects are ignored.
public static Map<String,JsonSimple> toJavaMap(JsonObject object)
Take all of the JsonObjects found in a JsonObject, wrap them in JsonSimple objects, then add to a Java Map and return.
All entries found that are not JsonObjects are ignored.
public static Map<String,JsonObject> fromJavaMap(Map<String,JsonSimple> from)
Take all of the JsonSimple objects in the given Map and return a Map having replace them all with their base JsonObjects.
Useful in when combining stacks of JSON objects.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||