Class JsonPrimitive

java.lang.Object
net.luis.utils.io.data.json.JsonPrimitive
All Implemented Interfaces:
JsonElement, ValueGetter

public class JsonPrimitive extends Object implements JsonElement, ValueGetter
Represents a json primitive value.
A primitive value can be a boolean, number or string.
  • Field Details

    • value

      private final String value
      The value of this json primitive.
  • Constructor Details

    • JsonPrimitive

      public JsonPrimitive(boolean value)
      Constructs a new json primitive with the given boolean value.
      Parameters:
      value - The boolean value
    • JsonPrimitive

      public JsonPrimitive(@NotNull @NotNull Number value)
      Constructs a new json primitive with the given number value.
      Parameters:
      value - The number value
      Throws:
      NullPointerException - If the value is null
    • JsonPrimitive

      public JsonPrimitive(@NotNull @NotNull String value)
      Constructs a new json primitive with the given string value.
      Parameters:
      value - The string value
      Throws:
      NullPointerException - If the value is null
  • Method Details

    • tryParse

      @NotNull private static @NotNull Object tryParse(@NotNull @NotNull String string)
      Tries to parse the given string to a boolean or number.
      Parameters:
      string - The string
      Returns:
      The parsed value or the string if it could not be parsed
    • getAsString

      @NotNull public @NotNull String getAsString()
      Description copied from interface: ValueGetter
      Returns the value which is hold by this object as a string.
      Specified by:
      getAsString in interface ValueGetter
      Returns:
      The value as a string
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      @NotNull public @NotNull String toString(@Nullable @Nullable JsonConfig config)
      Description copied from interface: JsonElement
      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.
      Specified by:
      toString in interface JsonElement
      Parameters:
      config - The json config to use
      Returns:
      The string representation of this json element