Package com.clumd.projects.javajson.api
Interface Json
- All Superinterfaces:
JsonGenerator,Serializable
public interface Json extends JsonGenerator, Serializable
Defines the required methods callable on a JSON object, to get type-safe properties, check existence,
and convert to various degrees of string (pretty print etc).
-
Method Summary
Modifier and Type Method Description StringasPrettyString()Calls asPrettyString with the deepest depth and a default indent width of 4.StringasPrettyString(int depth)Creates a string representation of the current object with a given depth of object expansionStringasPrettyString(int depth, int indentWidth)Creates a string representation of the current object with a given depth of object expansion And a custom level of indentationStringasString()Calls as string with the deepest depthStringasString(int depth)Creates a string representation of the current object with a given depth of object expansionbooleancontains(String key)Used to check if a given key is present in this JSON object (Object in this sentence refers to any JSON data-type).booleancontainsAllKeys(Collection<String> keys)Used to check if every provided key appears in the current JSON object.JsoncreateFromMultilineString(List<String> jsonFragment)Convert the contents of consecutive Strings into the JSON representation of them.JsoncreateFromString(String jsonFragment)Convert the contents of a String into the JSON representation.booleanequals(Object other)Replica of the .equals on a class, but used to enforce that implementors will override.JsongetAny()Used to get the JSON datatype of the current object regardless of the underlying datatype it represents.JsongetAnyAt(String key)The same asgetAny, but at a path in the JSON given by key.List<Json>getArray()Used to get the array value of this JSON object, if it was itself, an array.List<Json>getArrayAt(String key)The same asgetArray, but at a path in the JSON given by key.booleangetBoolean()Used to get the boolean value of this JSON object, if it was itself, a boolean.booleangetBooleanAt(String key)The same asgetBoolean, but at a path in the JSON given by key.JSTypegetDataType()Used to figure out which Datatype this JSON object represents from the JSON standard.JSTypegetDataTypeOf(String key)The same asgetDataType, but at a path in the JSON given by key.doublegetDouble()Used to get the double value of this JSON object, if it was itself, a double.doublegetDoubleAt(String key)The same asgetDouble, but at a path in the JSON given by key.JsongetJSONObject()Used to get the Object value of this JSON object, if it was itself, an Object.JsongetJSONObjectAt(String key)The same asgetJSONObject, but at a path in the JSON given by key.List<String>getKeys()Used to get a list of all possible keys available at the current depth/level of json.List<String>getKeysOf(String key)The same asgetKeys, but at a path in the JSON given by key.longgetLong()Used to get the long value of this JSON object, if it was itself, a long.longgetLongAt(String key)The same asgetLong, but at a path in the JSON given by key.StringgetString()Used to get the string value of this JSON object, if it was itself, a string.StringgetStringAt(String key)The same asgetString, but at a path in the JSON given by key.ObjectgetValue()Used to get the underlying value of each JSON datatype in a non-typesafe manner.ObjectgetValueAt(String key)The same asgetValue, but at a path in the JSON given by key.List<Json>getValues()Used to get a list of all values of the current JSON object.List<Json>getValuesOf(String key)The same asgetValues, but at a path in the JSON given by key.inthashCode()Used to enforce the implementation of a Hashcode on ImplementersStringtoPrettyString()Calls asPrettyString with the shallowest depth and a default indent width of 4.StringtoString()Calls as string with the shallowest depth
-
Method Details
-
createFromString
Convert the contents of a String into the JSON representation.- Parameters:
jsonFragment- A string to be converted.- Returns:
- A JSON object representing the contents of the string.
- Throws:
JsonParseException- Thrown if the string was not valid JSON syntax.
-
createFromMultilineString
Convert the contents of consecutive Strings into the JSON representation of them.- Parameters:
jsonFragment- A list of strings (usually originating from each line of a .json file), for a single JSON.- Returns:
- A JSON object representing the contents of the list of strings.
- Throws:
JsonParseException- Thrown if any of the input contains invalid JSON syntax.
-
contains
Used to check if a given key is present in this JSON object (Object in this sentence refers to any JSON data-type).- Parameters:
key- The path within the JSON to check for existence.- Returns:
- True if a value was found at the given key, false if not.
-
containsAllKeys
Used to check if every provided key appears in the current JSON object.- Parameters:
keys- The collection of JSON key paths to check for existence.- Returns:
- True if every key in the collection was found, False if one or more keys was missing from the JSON.
-
getValue
Object getValue()Used to get the underlying value of each JSON datatype in a non-typesafe manner.- Returns:
- The Java data value this JSON object wraps.
-
getDataType
JSType getDataType()Used to figure out which Datatype this JSON object represents from the JSON standard.- Returns:
- The datatype of this JSON object.
-
getKeys
Used to get a list of all possible keys available at the current depth/level of json.I.e. if you have an object where each child has its own properties, you will only get a list of the children, NOT of the children's children.
- Returns:
- The list of all possible keys of this JSON object.
-
getValues
Used to get a list of all values of the current JSON object.- Returns:
- The list of all values of this JSON object.
-
getArray
Used to get the array value of this JSON object, if it was itself, an array.- Returns:
- The Array value of the current JSON object.
- Throws:
KeyDifferentTypeException- Thrown if this JSON object represents something other than an array.
-
getBoolean
Used to get the boolean value of this JSON object, if it was itself, a boolean.- Returns:
- The boolean value of the current JSON object.
- Throws:
KeyDifferentTypeException- Thrown if this JSON object represents something other than a boolean.
-
getDouble
Used to get the double value of this JSON object, if it was itself, a double.- Returns:
- The double value of the current JSON object.
- Throws:
KeyDifferentTypeException- Thrown if this JSON object represents something other than an double.
-
getLong
Used to get the long value of this JSON object, if it was itself, a long.- Returns:
- The long value of the current JSON object.
- Throws:
KeyDifferentTypeException- Thrown if this JSON object represents something other than an long.
-
getString
Used to get the string value of this JSON object, if it was itself, a string.You should NOT use this method to get the String representation of this object, see
toStringstyle methods.- Returns:
- The string value of the current JSON object.
- Throws:
KeyDifferentTypeException- Thrown if this JSON object represents something other than a string.
-
getJSONObject
Used to get the Object value of this JSON object, if it was itself, an Object.- Returns:
- The Object value of the current JSON object.
- Throws:
KeyDifferentTypeException- Thrown if this JSON object represents something other than an Object.
-
getAny
Json getAny()Used to get the JSON datatype of the current object regardless of the underlying datatype it represents.- Returns:
- The current object as a JSON regardless of the underlying datatype it represents.
-
getValueAt
The same asgetValue, but at a path in the JSON given by key.- Parameters:
key- The key / path from the current JSON object to the target you want.- Returns:
- Any value (non-type safe) present at the given key.
- Throws:
JsonKeyException- Thrown if they key is malformed, or there was not a property at the provided key.
-
getJSONObjectAt
The same asgetJSONObject, but at a path in the JSON given by key.- Parameters:
key- The key / path from the current JSON object to the target you want.- Returns:
- Any JSON OBJECT type present at the given key.
- Throws:
JsonKeyException- Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not OBJECT.
-
getDataTypeOf
The same asgetDataType, but at a path in the JSON given by key.- Parameters:
key- The key / path from the current JSON object to the target you want.- Returns:
- The JSON datatype present at the given key.
- Throws:
JsonKeyException- Thrown if they key is malformed, or there was not a property at the provided key.
-
getKeysOf
The same asgetKeys, but at a path in the JSON given by key.- Parameters:
key- The key / path from the current JSON object to the target you want.- Returns:
- A list of all possible keys present from the point the given key.
- Throws:
JsonKeyException- Thrown if they key is malformed, or there was not a property at the provided key.
-
getValuesOf
The same asgetValues, but at a path in the JSON given by key.- Parameters:
key- The key / path from the current JSON object to the target you want.- Returns:
- All values present from the given key.
- Throws:
JsonKeyException- Thrown if they key is malformed, or there was not a property at the provided key.
-
getArrayAt
The same asgetArray, but at a path in the JSON given by key.- Parameters:
key- The key / path from the current JSON object to the target you want.- Returns:
- Any JSON ARRAY type present at the given key.
- Throws:
JsonKeyException- Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not ARRAY.
-
getBooleanAt
The same asgetBoolean, but at a path in the JSON given by key.- Parameters:
key- The key / path from the current JSON object to the target you want.- Returns:
- Any JSON BOOLEAN type present at the given key.
- Throws:
JsonKeyException- Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not BOOLEAN.
-
getDoubleAt
The same asgetDouble, but at a path in the JSON given by key.- Parameters:
key- The key / path from the current JSON object to the target you want.- Returns:
- Any JSON DOUBLE type present at the given key.
- Throws:
JsonKeyException- Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not DOUBLE.
-
getLongAt
The same asgetLong, but at a path in the JSON given by key.- Parameters:
key- The key / path from the current JSON object to the target you want.- Returns:
- Any JSON LONG type present at the given key.
- Throws:
JsonKeyException- Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not LONG.
-
getStringAt
The same asgetString, but at a path in the JSON given by key.You should NOT use this method to get the String representation of this object, see
toStringstyle methods.- Parameters:
key- The key / path from the current JSON object to the target you want.- Returns:
- Any JSON STRING type present at the given key.
- Throws:
JsonKeyException- Thrown if they key is malformed, there was not a property at the provided key, or the datatype of the value at key, was not STRING.
-
getAnyAt
The same asgetAny, but at a path in the JSON given by key.- Parameters:
key- The key / path from the current JSON object to the target you want.- Returns:
- The Java wrapping JSON data present at the given key.
- Throws:
JsonKeyException- Thrown if they key is malformed, there was not a property at the provided key.
-
toString
String toString()Calls as string with the shallowest depth -
toPrettyString
String toPrettyString()Calls asPrettyString with the shallowest depth and a default indent width of 4.- Returns:
- The highest level view of the current object, with new lines and object indentation
-
asString
String asString()Calls as string with the deepest depth- Returns:
- The most detailed view of the current object
-
asString
Creates a string representation of the current object with a given depth of object expansion- Parameters:
depth- The depth of objects to show in the output- Returns:
- The string representation of this object
-
asPrettyString
String asPrettyString()Calls asPrettyString with the deepest depth and a default indent width of 4.- Returns:
- The most detailed view of the current object, with new lines and object indentation
-
asPrettyString
Creates a string representation of the current object with a given depth of object expansion- Parameters:
depth- The depth of objects to show in the output- Returns:
- The string representation of this object, with new lines and object indentation
-
asPrettyString
Creates a string representation of the current object with a given depth of object expansion And a custom level of indentation- Parameters:
depth- The depth of objects to show in the outputindentWidth- How wide each subsequent indentation should be on child properties.- Returns:
- The string representation of this object, with new lines and object indentation
-
equals
Replica of the .equals on a class, but used to enforce that implementors will override. -
hashCode
int hashCode()Used to enforce the implementation of a Hashcode on Implementers
-