Class Json
java.lang.Object
codes.grow.packages.betterstack.core.Json
Shared Jackson configuration of the SDK.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tdecode(byte[] bytes, com.fasterxml.jackson.core.type.TypeReference<T> type) Decodes JSON bytes into a generic type.static <T> TDecodes JSON bytes into a type.static byte[]Encodes a value as UTF-8 JSON.static com.fasterxml.jackson.databind.ObjectMappermapper()Returns the shared mapper.static StringEncodes a value as a JSON string.static com.fasterxml.jackson.databind.JsonNodetree(byte[] bytes) Parses JSON bytes into a tree.
-
Method Details
-
mapper
public static com.fasterxml.jackson.databind.ObjectMapper mapper()Returns the shared mapper. Do not reconfigure it.- Returns:
- the mapper
-
encode
Encodes a value as UTF-8 JSON.- Parameters:
value- any Jackson-serialisable value- Returns:
- the bytes
- Throws:
ValidationException- when the value cannot be encoded
-
stringify
Encodes a value as a JSON string.- Parameters:
value- any Jackson-serialisable value- Returns:
- the JSON text
- Throws:
ValidationException- when the value cannot be encoded
-
decode
Decodes JSON bytes into a type.- Type Parameters:
T- target type- Parameters:
bytes- UTF-8 JSONtype- target class- Returns:
- the value
- Throws:
ValidationException- when the bytes are not valid JSON for the type
-
decode
public static <T> T decode(byte[] bytes, com.fasterxml.jackson.core.type.TypeReference<T> type) Decodes JSON bytes into a generic type.- Type Parameters:
T- target type- Parameters:
bytes- UTF-8 JSONtype- target type reference- Returns:
- the value
- Throws:
ValidationException- when the bytes are not valid JSON for the type
-
tree
public static com.fasterxml.jackson.databind.JsonNode tree(byte[] bytes) Parses JSON bytes into a tree.- Parameters:
bytes- UTF-8 JSON- Returns:
- the tree
- Throws:
ValidationException- when the bytes are not valid JSON
-