Interface JsonOperations.JsonPathResult

Enclosing interface:
JsonOperations<K>

public static interface JsonOperations.JsonPathResult
Combined result of reading several paths from a single JSON document.

The as(Class) methods deserialize an object with one property per requested path. Property names correspond to the path strings supplied to JsonOperations.paths(Object, Collection). Each property's value is extracted from that path's match array. A path with no matches contributes JSON null. Use path(String) to access the matches for an individual path.

The raw JSON.GET response contains a match array for a single requested path. For multiple paths, it contains an object keyed by the JSONPath expressions sent to Redis. Property paths are converted to bracket notation, so a request for "name" uses "$['name']" as the response key.

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

    • asBytes

      byte @Nullable [] asBytes()
      Return the JSON.GET response as raw bytes.

      The response retains the match arrays and any JSONPath keys returned by Redis.

      Returns:
      the JSON bytes, or null if the key does not exist.
    • asString

      default @Nullable String asString()
      Return the JSON.GET response as a UTF-8 string.

      The response retains the match arrays and any JSONPath keys returned by Redis.

      Returns:
      the JSON string, or null if the key does not exist.
    • map

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

      The function receives the same representation as asBytes(), including the match arrays and any JSONPath keys. 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 response bytes.
      Returns:
      the function result, or null if the key does not exist.
    • as

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

      Each requested path contributes one property as described in JsonOperations.JsonPathResult. Use path(String) to access a path with multiple matches.

      Type Parameters:
      V - the result type.
      Parameters:
      type - the target type.
      Returns:
      the deserialized object, or null if the key does not exist.
      Throws:
      SerializationException - if a path has more than one match, or the object cannot be deserialized.
    • as

      Deserialize the selected values into an object of the given type.

      Each requested path contributes one property as described in JsonOperations.JsonPathResult. Use path(String) to access a path with multiple matches.

      Type Parameters:
      V - the result type.
      Parameters:
      type - the target type.
      Returns:
      the deserialized object, or null if the key does not exist.
      Throws:
      SerializationException - if a path has more than one match, or the object cannot be deserialized.
    • path

      Return the result for a requested path.

      The result contains the path's match array and supports any number of matches.

      Parameters:
      path - the path string supplied to JsonOperations.paths(Object, Collection), must not be null.
      Returns:
      the result for the requested path.
      Throws:
      IllegalArgumentException - if the path was not requested.
    • exists

      boolean exists()
      Return whether the key exists.

      An existing key may have no matches for individual paths.

      Returns:
      true if the key exists; false otherwise.