Package io.dapr.utils
Class DefaultContentTypeConverter
- java.lang.Object
-
- io.dapr.utils.DefaultContentTypeConverter
-
public class DefaultContentTypeConverter extends Object
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
Constructors Constructor Description DefaultContentTypeConverter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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)
-
-
-
Method Detail
-
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
public static boolean isCloudEventContentType(String contentType)
-
isJsonContentType
public static boolean isJsonContentType(String contentType)
-
isStringContentType
public static boolean isStringContentType(String contentType)
-
isBinaryContentType
public static boolean isBinaryContentType(String contentType)
-
-