Package sk.antons.json
Interface JsonValue
- All Known Subinterfaces:
JsonArray,JsonBoolLiteral,JsonExpLiteral,JsonFracLiteral,JsonIntLiteral,JsonLiteral,JsonNullLiteral,JsonObject,JsonStringLiteral
- All Known Implementing Classes:
JsonArrayImpl,JsonBoolLiteralImpl,JsonExpLiteralImpl,JsonFracLiteralImpl,JsonIntLiteralImpl,JsonLiteralImpl,JsonNullLiteralImpl,JsonObjectImpl,JsonStringLiteralImpl,JsonValueImpl
public interface JsonValue
Generic json value. Represents all object, arrays and literals.
- Author:
- antons
-
Method Summary
Modifier and TypeMethodDescriptionasArray()Cast this value instance to JsonArrayCast this value instance to JsonBoolLiteralCast this value instance to JsonExpLiteralImplCast this value instance to JsonFracLiteralCast this value instance to JsonIntLiteralCast this value instance to JsonLiteralCast this value instance to JsonNullLiteralasObject()Cast this value instance to JsonObjectCast this value instance to JsonStringLiteralConverts value to value usable for some template frameworks.copy()Makes deep copy of this value.Finder for specified path.find(PathMatcher matcher) Finder for specified matcher.findAll(PathMatcher matcher) Find all json values with defined pathfindAllLiterals(PathMatcher matcher) Find all json value with defined path and converts them to string valuefindFirst(PathMatcher matcher) Find first json value with defined pathfindFirstLiteral(PathMatcher matcher) Find first json value with defined path and converts it to string valuebooleanisArray()Checks if this value is instance of JsonArraybooleanChecks if this value is instance of JsonBoolLiteralbooleanisDescendantOf(JsonValue parent) Returns true is this value is descendant of parent value;booleanChecks if this value is instance of JsonExpLiteralbooleanChecks if this value is instance of JsonFracLiteralbooleanChecks if this value is instance of JsonIntLiteralbooleanChecks if this value is instance of JsonLiteralbooleanChecks if this value is instance of JsonNullLiteralbooleanisObject()Checks if this value is instance of JsonObjectbooleanChecks if this value is instance of JsonStringLiteralname()Returns name of the instance derived from parent.parent()Parent of this value in json structureintIndex of this instance in parent objectString[]path()Returns path of this value in json structureReturns path of this value in json structurevoidremove()Removes this instance from parent object.voidReplaces this instance in parent object by this value.Produces compact string representation of this json value.toPrettyString(String indent) Produces pretty (readable) string representation of this json value.voidwriteCompact(Appendable appendable) Produces compact string representation of this json value.voidwritePretty(Appendable appendable, String indent) Produces pretty (readable) string representation of this json value.
-
Method Details
-
writeCompact
Produces compact string representation of this json value.- Parameters:
appendable- place where json string will be written.
-
toCompactString
String toCompactString()Produces compact string representation of this json value.- Returns:
- compact string value
-
writePretty
Produces pretty (readable) string representation of this json value.- Parameters:
appendable- place where json string will be written.indent- string used for indend nested levels. (ussually tab or some spaces)
-
toPrettyString
Produces pretty (readable) string representation of this json value.- Parameters:
indent- string used for indend nested levels. (ussually tab or some spaces)- Returns:
- pretty string value
-
asObject
JsonObject asObject()Cast this value instance to JsonObject- Returns:
- this value instance bud narrow casted to JsonObject.
-
asArray
JsonArray asArray()Cast this value instance to JsonArray- Returns:
- this value instance bud narrow casted to JsonArray.
-
asNullLiteral
JsonNullLiteral asNullLiteral()Cast this value instance to JsonNullLiteral- Returns:
- this value instance bud narrow casted to JsonNullLiteral.
-
asBoolLiteral
JsonBoolLiteral asBoolLiteral()Cast this value instance to JsonBoolLiteral- Returns:
- this value instance bud narrow casted to JsonBoolLiteral.
-
asExpLiteral
JsonExpLiteral asExpLiteral()Cast this value instance to JsonExpLiteralImpl- Returns:
- this value instance bud narrow casted to JsonExpLiteral.
-
asFracLiteral
JsonFracLiteral asFracLiteral()Cast this value instance to JsonFracLiteral- Returns:
- this value instance bud narrow casted to JsonFracLiteral.
-
asIntLiteral
JsonIntLiteral asIntLiteral()Cast this value instance to JsonIntLiteral- Returns:
- this value instance bud narrow casted to JsonIntLiteral.
-
asStringLiteral
JsonStringLiteral asStringLiteral()Cast this value instance to JsonStringLiteral- Returns:
- this value instance bud narrow casted to JsonStringLiteral.
-
asLiteral
JsonLiteral asLiteral()Cast this value instance to JsonLiteral- Returns:
- this value instance bud narrow casted to JsonLiteral.
-
isObject
boolean isObject()Checks if this value is instance of JsonObject- Returns:
- result of the check
-
isArray
boolean isArray()Checks if this value is instance of JsonArray- Returns:
- result of the check
-
isNullLiteral
boolean isNullLiteral()Checks if this value is instance of JsonNullLiteral- Returns:
- result of the check
-
isBoolLiteral
boolean isBoolLiteral()Checks if this value is instance of JsonBoolLiteral- Returns:
- result of the check
-
isExpLiteral
boolean isExpLiteral()Checks if this value is instance of JsonExpLiteral- Returns:
- result of the check
-
isFracLiteral
boolean isFracLiteral()Checks if this value is instance of JsonFracLiteral- Returns:
- result of the check
-
isIntLiteral
boolean isIntLiteral()Checks if this value is instance of JsonIntLiteral- Returns:
- result of the check
-
isStringLiteral
boolean isStringLiteral()Checks if this value is instance of JsonStringLiteral- Returns:
- result of the check
-
isLiteral
boolean isLiteral()Checks if this value is instance of JsonLiteral- Returns:
- result of the check
-
find
Finder for specified matcher.- Parameters:
matcher- Matcher to used for identifying returned values.- Returns:
- helper class instance.
-
find
Finder for specified path. (SimplePathMather is used)- Parameters:
path- path used for identifying returned values- Returns:
- helper class instance.
-
findAll
Find all json values with defined path- Parameters:
matcher- Matcher to used for identifying returned values.- Returns:
- all json values defined by path
-
findFirst
Find first json value with defined path- Parameters:
matcher- Matcher to used for identifying returned value.- Returns:
- first json value defined by path
-
findAllLiterals
Find all json value with defined path and converts them to string value- Parameters:
matcher- Matcher to used for identifying returned values.- Returns:
- all json value defined by path converted to string
-
findFirstLiteral
Find first json value with defined path and converts it to string value- Parameters:
matcher- Matcher to used for identifying returned value.- Returns:
- first json value defined by path converted to string
-
parent
JsonValue parent()Parent of this value in json structure- Returns:
- parent json value or null if this instance is root
-
parentIndex
int parentIndex()Index of this instance in parent object- Returns:
- index of this instance in parent object or -1 if this is root
-
path
String[] path()Returns path of this value in json structure- Returns:
- path of this instance
-
pathAsString
String pathAsString()Returns path of this value in json structure- Returns:
- path of this instance
-
remove
void remove()Removes this instance from parent object. -
replaceBy
Replaces this instance in parent object by this value. Do nothing if this object is root and works like remove() is new value is null;- Parameters:
newValue- new value which must replace this instance.
-
isDescendantOf
Returns true is this value is descendant of parent value;- Parameters:
parent- possible paretn value- Returns:
- true if parent is parent of this.
-
copy
JsonValue copy()Makes deep copy of this value.- Returns:
- copy of this
-
name
String name()Returns name of the instance derived from parent.- Returns:
- name of value in json tree or null if it is root.
-
asTemplateParam
Object asTemplateParam()Converts value to value usable for some template frameworks. - JsonObjects is converted to read only Map - JsonArray is converted to read only List - JsonLiteral is converted to its java value- Returns:
- template parameter form of this value
-