Interface JsonOperations.JsonResult

All Superinterfaces:
JsonValue
Enclosing interface:
JsonOperations<K>

public static interface JsonOperations.JsonResult extends JsonValue
The result of a JSON command, with access to its JSON representation and deserialized value.

A JSONPath query returns a match array containing zero or more values, including when the path selects the document root. Use as(Class) to deserialize a single match or matches() to access individual matches. A matched value can itself be an object, an array, or a scalar.

Results obtained from matches() represent individual values without a surrounding match array. The asBytes() and asString() methods preserve any match array present in this result.

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

    Modifier and Type
    Method
    Description
    <V> @Nullable V
    as(Class<V> type)
    Deserialize this result into an object of the given type.
    <V> @Nullable V
    Deserialize this result into an object of the given type.
    byte @Nullable []
    Return the JSON representation of this result as raw bytes.
    Return the JSON representation of this result as a UTF-8 string.
    boolean
    Return whether the key exists.
    boolean
    Return whether this result represents JSON null.
    default <U extends @Nullable Object>
    U
    map(Function<? super byte[], ? extends U> mapper)
    Apply the given function to the raw JSON bytes of this result.
    Return the individual matches in this result.
  • Method Details

    • as

      <V> @Nullable V as(Class<V> type)
      Deserialize this result into an object of the given type.

      If this result contains a match array, deserialize its single element. Use matches() to access multiple matches.

      Type Parameters:
      V - the result type.
      Parameters:
      type - the target type.
      Returns:
      the deserialized value, or null if the key is absent, the path has no matches, or the value is JSON null.
      Throws:
      SerializationException - if there is more than one match or the value cannot be deserialized.
    • as

      Deserialize this result into an object of the given type.

      If this result contains a match array, deserialize its single element. Use matches() to access multiple matches.

      Type Parameters:
      V - the result type.
      Parameters:
      type - the target type.
      Returns:
      the deserialized value, or null if the key is absent, the path has no matches, or the value is JSON null.
      Throws:
      SerializationException - if there is more than one match or the value cannot be deserialized.
    • matches

      Return the individual matches in this result.

      Each element of a match array becomes a separate JsonResult. For a result that already represents an individual value, return a sequence containing this result.

      Returns:
      the matches in order, or an empty sequence if the key is absent or the path has no matches.
    • asBytes

      byte @Nullable [] asBytes()
      Return the JSON representation of this result as raw bytes.

      The match array, if present, is retained. A result obtained directly from Redis preserves its original representation. For values extracted from a larger response, preservation depends on the configured RedisJsonSerializer. The built-in Jackson serializers preserve the original bytes.

      Specified by:
      asBytes in interface JsonValue
      Returns:
      the JSON bytes, or null if the key does not exist.
      See Also:
    • asString

      default @Nullable String asString()
      Return the JSON representation of this result as a UTF-8 string.

      The match array, if present, is retained.

      Specified by:
      asString in interface JsonValue
      Returns:
      the JSON string, or null if the key does not exist.
      See Also:
    • map

      default <U extends @Nullable Object> U map(Function<? super byte[], ? extends U> mapper)
      Apply the given function to the raw JSON bytes of this result.

      The function receives the same representation as asBytes(), including any match array or JSON null value. It is not invoked if the key does not exist.

      Type Parameters:
      U - the mapped result type.
      Parameters:
      mapper - the function to apply to the JSON bytes.
      Returns:
      the function result, or null if the key does not exist.
    • isNull

      boolean isNull()
      Return whether this result represents JSON null.

      For a match array, this method returns true only if the array contains a single JSON null value. It returns false if the key is absent or the path has no matches.

      Returns:
      true if this result represents JSON null; false otherwise.
      See Also:
    • exists

      boolean exists()
      Return whether the key exists.

      An existing key may have no matches for the selected path or contain a JSON null value.

      Returns:
      true if the key exists; false otherwise.
      See Also: