Package akka.javasdk
Class JsonSupport
Object
akka.javasdk.JsonSupport
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TdecodeJson(Class<T> valueClass, byte[] bytes) Decode the given bytes to an instance of T using Jackson.static <T> TdecodeJson(Class<T> valueClass, akka.util.ByteString bytes) Decode the given bytes to an instance of T using Jackson.static <T> akka.util.ByteStringencodeToAkkaByteString(T value) Encode the given value as JSON using Jackson.static <T> StringencodeToString(T value) Encode the given value as JSON using Jackson.static com.fasterxml.jackson.databind.ObjectMapperThe Jackson ObjectMapper that is used for encoding and decoding JSON for HTTP endpoints and HTTP requests.
-
Method Details
-
getObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()The Jackson ObjectMapper that is used for encoding and decoding JSON for HTTP endpoints and HTTP requests.You may adjust its configuration, but that must only be performed before starting the service, from
ServiceSetup.onStartup(). -
encodeToAkkaByteString
public static <T> akka.util.ByteString encodeToAkkaByteString(T value) Encode the given value as JSON using Jackson.- Parameters:
value- the object to encode as JSON, must be an instance of a class properly annotated with the needed Jackson annotations.- Throws:
IllegalArgumentException- if the given value cannot be turned into JSON
-
encodeToString
Encode the given value as JSON using Jackson.- Parameters:
value- the object to encode as JSON, must be an instance of a class properly annotated with the needed Jackson annotations.- Throws:
IllegalArgumentException- if the given value cannot be turned into JSON
-
decodeJson
Decode the given bytes to an instance of T using Jackson. The bytes must be the JSON string as bytes.- Parameters:
valueClass- The type of class to deserialize the object to, the class must have the proper Jackson annotations for deserialization.bytes- The bytes to deserialize.- Returns:
- The decoded object
- Throws:
IllegalArgumentException- if the given value cannot be decoded to a T
-
decodeJson
Decode the given bytes to an instance of T using Jackson. The bytes must be the JSON string as bytes.- Parameters:
valueClass- The type of class to deserialize the object to, the class must have the proper Jackson annotations for deserialization.bytes- The bytes to deserialize.- Returns:
- The decoded object
- Throws:
IllegalArgumentException- if the given value cannot be decoded to a T
-