Interface JsonElement

All Known Implementing Classes:
JsonArray, JsonNull, JsonObject, JsonPrimitive
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface JsonElement
A generic class representing a json element.
A json element can be a json object, a json array, a json primitive or a json null.
  • Method Summary

    Modifier and Type
    Method
    Description
    default @NotNull JsonArray
    Converts this json element to a json array.
    default @NotNull JsonObject
    Converts this json element to a json object.
    default @NotNull JsonPrimitive
    Converts this json element to a json primitive.
    private @NotNull String
    Returns the name of the class in a human-readable format.
    The name is the class name with spaces between the words and all letters in lower-case.
    Used for debugging and error messages.
    default boolean
    Checks if this json element is a json array.
    default boolean
    Checks if this json element is a json null.
    default boolean
    Checks if this json element is a json object.
    default boolean
    Checks if this json element is a json primitive.
    @NotNull String
    toString(@NotNull JsonConfig config)
    Returns a string representation of this json element based on the given json config.
    The json config specifies how the json element should be formatted.
  • Method Details

    • getName

      @NotNull private @NotNull String getName()
      Returns the name of the class in a human-readable format.
      The name is the class name with spaces between the words and all letters in lower-case.
      Used for debugging and error messages.
      Returns:
      The name of the class in a human-readable format
    • isJsonNull

      default boolean isJsonNull()
      Checks if this json element is a json null.
      Returns:
      True if this json element is a json null, false otherwise
    • isJsonObject

      default boolean isJsonObject()
      Checks if this json element is a json object.
      Returns:
      True if this json element is a json object, false otherwise
    • isJsonArray

      default boolean isJsonArray()
      Checks if this json element is a json array.
      Returns:
      True if this json element is a json array, false otherwise
    • isJsonPrimitive

      default boolean isJsonPrimitive()
      Checks if this json element is a json primitive.
      Returns:
      True if this json element is a json primitive, false otherwise
    • getAsJsonObject

      @NotNull default @NotNull JsonObject getAsJsonObject()
      Converts this json element to a json object.
      Returns:
      This json element as a json object
      Throws:
      JsonTypeException - If this json element is not a json object
    • getAsJsonArray

      @NotNull default @NotNull JsonArray getAsJsonArray()
      Converts this json element to a json array.
      Returns:
      This json element as a json array
      Throws:
      JsonTypeException - If this json element is not a json array
    • getAsJsonPrimitive

      @NotNull default @NotNull JsonPrimitive getAsJsonPrimitive()
      Converts this json element to a json primitive.
      Returns:
      This json element as a json primitive
      Throws:
      JsonTypeException - If this json element is not a json primitive
    • toString

      @NotNull @NotNull String toString(@NotNull @NotNull JsonConfig config)
      Returns a string representation of this json element based on the given json config.
      The json config specifies how the json element should be formatted.
      Parameters:
      config - The json config to use
      Returns:
      The string representation of this json element