Interface JsonOperations.JsonResult
- All Superinterfaces:
JsonValue
- Enclosing interface:
JsonOperations<K>
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 TypeMethodDescription<V> @Nullable VDeserialize this result into an object of the given type.<V> @Nullable Vas(ParameterizedTypeReference<V> type) Deserialize this result into an object of the given type.byte @Nullable []asBytes()Return the JSON representation of this result as raw bytes.asString()Return the JSON representation of this result as a UTF-8 string.booleanexists()Return whether the key exists.booleanisNull()Return whether this result represents JSON null.Apply the given function to the raw JSON bytes of this result.matches()Return the individual matches in this result.
-
Method Details
-
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.
-
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
JsonOperations.JsonResults 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. -
asString
-
map
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:
-