Class JsonString

java.lang.Object
com.revetsec.json.JsonString
All Implemented Interfaces:
JsonValue

@Immutable public final class JsonString extends Object implements JsonValue
A JSON string.

Its value is well-formed UTF-16: an unpaired surrogate is rejected. It may hold any other character, including NUL and Unicode noncharacters, and it compares exactly, with no case folding or normalization.

Since:
1.0.0
Author:
Mark Allen
  • Method Details

    • fromValue

      public static @NonNull JsonString fromValue(@NonNull String value)
      Returns a JSON string holding value.
      Parameters:
      value - the string's value
      Returns:
      the JSON string
      Throws:
      NullPointerException - if value is null
      IllegalArgumentException - if value contains an unpaired surrogate
      Since:
      1.0.0
    • getValue

      Returns this string's value, which may be a secret or personal data.
      Returns:
      the value
      Since:
      1.0.0
    • toJson

      Description copied from interface: JsonValue
      Serializes this value as compact JSON text: no insignificant whitespace, members in insertion order, and numbers in the canonical form of BigDecimal.toString() (1e2 becomes 1E+2).

      Strings escape only what JSON requires: the quotation mark, the reverse solidus and the control characters U+0000 to U+001F, using the two-character escapes where they exist. Every other character, U+2028 and U+2029 included, is written as itself.

      Unlike toString(), the result contains every string and number this value holds. It is not the text a value was parsed from, so never verify a signature over it.

      Specified by:
      toJson in interface JsonValue
      Returns:
      the JSON text
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • hashCode

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

      Overrides:
      toString in class Object