Package io.dapr.utils
Class DefaultContentTypeConverter
java.lang.Object
io.dapr.utils.DefaultContentTypeConverter
A utility class for converting event to bytes based on content type or given serializer.
When an application/json or application/cloudevents+json is given as content type, the object serializer is used
to serialize the data into bytes
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
convertBytesToEventFromGrpc
(byte[] event, String contentType, TypeRef<T> typeRef) Function to convert a bytes array from gRPC input into event based on given object deserializer.static <T> T
convertBytesToEventFromHttp
(byte[] event, String contentType, TypeRef<T> typeRef) Function to convert a bytes array from HTTP input into event based on given object deserializer.static <T> byte[]
convertEventToBytesForGrpc
(T event, String contentType) Function to convert a given event to bytes for gRPC calls.static <T> byte[]
convertEventToBytesForHttp
(T event, String contentType) Function to convert a given event to bytes for HTTP calls.static boolean
isBinaryContentType
(String contentType) static boolean
isCloudEventContentType
(String contentType) static boolean
isJsonContentType
(String contentType) static boolean
isStringContentType
(String contentType)
-
Constructor Details
-
DefaultContentTypeConverter
public DefaultContentTypeConverter()
-
-
Method Details
-
convertEventToBytesForHttp
public static <T> byte[] convertEventToBytesForHttp(T event, String contentType) throws IllegalArgumentException, IOException Function to convert a given event to bytes for HTTP calls.- Type Parameters:
T
- The type of the event- Parameters:
event
- The input eventcontentType
- The content type of the event- Returns:
- the event as bytes
- Throws:
IllegalArgumentException
- on mismatch between contentType and event typesIOException
- on serialization
-
convertEventToBytesForGrpc
public static <T> byte[] convertEventToBytesForGrpc(T event, String contentType) throws IllegalArgumentException, IOException Function to convert a given event to bytes for gRPC calls.- Type Parameters:
T
- The type of the event- Parameters:
event
- The input eventcontentType
- The content type of the event- Returns:
- the event as bytes
- Throws:
IllegalArgumentException
- on mismatch between contentType and event typesIOException
- on serialization
-
convertBytesToEventFromHttp
public static <T> T convertBytesToEventFromHttp(byte[] event, String contentType, TypeRef<T> typeRef) throws IllegalArgumentException, IOException Function to convert a bytes array from HTTP input into event based on given object deserializer.- Type Parameters:
T
- The type of the event- Parameters:
event
- The input eventcontentType
- The content type of the eventtypeRef
- The type to convert the event to- Returns:
- the event as bytes
- Throws:
IllegalArgumentException
- on mismatch between contentType and event typesIOException
- on serialization
-
convertBytesToEventFromGrpc
public static <T> T convertBytesToEventFromGrpc(byte[] event, String contentType, TypeRef<T> typeRef) throws IllegalArgumentException, IOException Function to convert a bytes array from gRPC input into event based on given object deserializer.- Type Parameters:
T
- The type of the event- Parameters:
event
- The input eventcontentType
- The content type of the eventtypeRef
- The type to convert the event to- Returns:
- the event as bytes
- Throws:
IllegalArgumentException
- on mismatch between contentType and event typesIOException
- on serialization
-
isCloudEventContentType
-
isJsonContentType
-
isStringContentType
-
isBinaryContentType
-