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 TypeMethodDescriptionbyte[]asBytes()Return the JSON representation of this value as UTF-8 bytes.asString()Return the JSON representation of this value as a string.static JsonValueReturn a value representing JSON null.static JsonValueof(boolean value) Create a JSON boolean from the given value.static JsonValueof(double number) Create a JSON number from the givendouble.static JsonValueof(float number) Create a JSON number from the givenfloat.static JsonValueof(int number) Create a JSON number from the givenint.static JsonValueof(long number) Create a JSON number from the givenlong.static JsonValueCreate a JSON number from the givenNumber.static JsonValueCreate a JSON string from the given Java string.static JsonValueraw(byte[] json) Create a value from the given JSON bytes.static JsonValueCreate a value from the given JSON string.
-
Method Details
-
nullValue
-
of
Create a JSON boolean from the given value.- Parameters:
value- the boolean value.- Returns:
- the JSON boolean value.
-
of
-
of
Create a JSON number from the givenint.- Parameters:
number- the number to represent.- Returns:
- the JSON number value.
-
of
Create a JSON number from the givenlong.- Parameters:
number- the number to represent.- Returns:
- the JSON number value.
-
of
Create a JSON number from the givenfloat.- Parameters:
number- the number to represent, must be finite.- Returns:
- the JSON number value.
- Throws:
IllegalArgumentException- if the number is not finite.
-
of
Create a JSON number from the givendouble.- Parameters:
number- the number to represent, must be finite.- Returns:
- the JSON number value.
- Throws:
IllegalArgumentException- if the number is not finite.
-
of
-
raw
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
-
asBytes
byte[] asBytes()Return the JSON representation of this value as UTF-8 bytes.- Returns:
- the JSON bytes, including the literal
nullfornullValue().
-
asString
String asString()Return the JSON representation of this value as a string.- Returns:
- the JSON string, including
"null"fornullValue().
-