Interface JsonValue

All Known Subinterfaces:
JsonOperations.JsonResult

public interface JsonValue
A JSON value for use with RedisJsonCommands.

Use the of factory methods to convert Java scalar values to JSON. Use raw(String) or raw(byte[]) for an existing JSON representation. Raw values are accepted without validation.

Since:
4.2
Author:
Yordan Tsintsov, Mark Paluch, Moritz Halbritter
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Return the JSON representation of this value as UTF-8 bytes.
    Return the JSON representation of this value as a string.
    static JsonValue
    Return a value representing JSON null.
    static JsonValue
    of(boolean value)
    Create a JSON boolean from the given value.
    static JsonValue
    of(double number)
    Create a JSON number from the given double.
    static JsonValue
    of(float number)
    Create a JSON number from the given float.
    static JsonValue
    of(int number)
    Create a JSON number from the given int.
    static JsonValue
    of(long number)
    Create a JSON number from the given long.
    static JsonValue
    of(Number number)
    Create a JSON number from the given Number.
    static JsonValue
    of(String value)
    Create a JSON string from the given Java string.
    static JsonValue
    raw(byte[] json)
    Create a value from the given JSON bytes.
    static JsonValue
    raw(String json)
    Create a value from the given JSON string.
  • Method Details

    • nullValue

      static JsonValue nullValue()
      Return a value representing JSON null.
      Returns:
      the JSON null value.
    • of

      static JsonValue of(boolean value)
      Create a JSON boolean from the given value.
      Parameters:
      value - the boolean value.
      Returns:
      the JSON boolean value.
    • of

      static JsonValue of(Number number)
      Create a JSON number from the given Number.
      Parameters:
      number - the number to represent.
      Returns:
      the JSON number value.
    • of

      static JsonValue of(int number)
      Create a JSON number from the given int.
      Parameters:
      number - the number to represent.
      Returns:
      the JSON number value.
    • of

      static JsonValue of(long number)
      Create a JSON number from the given long.
      Parameters:
      number - the number to represent.
      Returns:
      the JSON number value.
    • of

      static JsonValue of(float number)
      Create a JSON number from the given float.
      Parameters:
      number - the number to represent, must be finite.
      Returns:
      the JSON number value.
      Throws:
      IllegalArgumentException - if the number is not finite.
    • of

      static JsonValue of(double number)
      Create a JSON number from the given double.
      Parameters:
      number - the number to represent, must be finite.
      Returns:
      the JSON number value.
      Throws:
      IllegalArgumentException - if the number is not finite.
    • of

      static JsonValue of(String value)
      Create a JSON string from the given Java string.

      The value is quoted and escaped as required by JSON string syntax.

      Parameters:
      value - the string to represent.
      Returns:
      the JSON string value.
      See Also:
    • raw

      static JsonValue raw(byte[] json)
      Create a value from the given JSON bytes.

      The bytes are used without validation or conversion.

      Parameters:
      json - a valid JSON value encoded as UTF-8.
      Returns:
      the JSON value.
    • raw

      static JsonValue raw(String json)
      Create a value from the given JSON string.

      The string is encoded as UTF-8 without validation, quoting, or escaping.

      Parameters:
      json - a valid JSON value.
      Returns:
      the JSON value.
      See Also:
    • asBytes

      byte[] asBytes()
      Return the JSON representation of this value as UTF-8 bytes.
      Returns:
      the JSON bytes, including the literal null for nullValue().
    • asString

      String asString()
      Return the JSON representation of this value as a string.
      Returns:
      the JSON string, including "null" for nullValue().