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 Details

    • writeCompact

      void writeCompact(Appendable appendable)
      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

      void writePretty(Appendable appendable, String indent)
      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

      String toPrettyString(String indent)
      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

      PathFinder find(PathMatcher matcher)
      Finder for specified matcher.
      Parameters:
      matcher - Matcher to used for identifying returned values.
      Returns:
      helper class instance.
    • find

      PathFinder find(String... path)
      Finder for specified path. (SimplePathMather is used)
      Parameters:
      path - path used for identifying returned values
      Returns:
      helper class instance.
    • findAll

      List<JsonValue> findAll(PathMatcher matcher)
      Find all json values with defined path
      Parameters:
      matcher - Matcher to used for identifying returned values.
      Returns:
      all json values defined by path
    • findFirst

      JsonValue findFirst(PathMatcher matcher)
      Find first json value with defined path
      Parameters:
      matcher - Matcher to used for identifying returned value.
      Returns:
      first json value defined by path
    • findAllLiterals

      List<String> findAllLiterals(PathMatcher matcher)
      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

      String findFirstLiteral(PathMatcher matcher)
      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

      void replaceBy(JsonValue newValue)
      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

      boolean isDescendantOf(JsonValue parent)
      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