Package fr.ght1pc9kc.testy.beat.utils
Class DeliveryMappingHelper
java.lang.Object
fr.ght1pc9kc.testy.beat.utils.DeliveryMappingHelper
Utility class used to convert the body of AMQP
Delivery
to POJO and reverse.
This class is implemented to avoid catching IOException
in all the test classes.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
readDeliveryValue
(com.rabbitmq.client.Delivery delivery, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.fasterxml.jackson.core.type.TypeReference<? extends T> typeReference) Map a delivery to java Object.static <T> T
readDeliveryValue
(com.rabbitmq.client.Delivery delivery, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<? extends T> clazz) Map a delivery to java Object.static byte[]
writeObjectAsByte
(Object toWrite, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Write an object as bytes.
-
Method Details
-
readDeliveryValue
public static <T> T readDeliveryValue(com.rabbitmq.client.Delivery delivery, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<? extends T> clazz) Map a delivery to java Object.- Type Parameters:
T
- Type of the target object.- Parameters:
delivery
- Delivery to map.objectMapper
- Object mapper to perform the conversion.clazz
- Class of the target object.- Returns:
- The converted object.
-
readDeliveryValue
public static <T> T readDeliveryValue(com.rabbitmq.client.Delivery delivery, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.fasterxml.jackson.core.type.TypeReference<? extends T> typeReference) Map a delivery to java Object.- Type Parameters:
T
- Type of the target object.- Parameters:
delivery
- Delivery to map.objectMapper
- Object mapper to perform the conversion.typeReference
- Type reference of the target object.- Returns:
- The converted object.
-
writeObjectAsByte
public static byte[] writeObjectAsByte(Object toWrite, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Write an object as bytes.- Parameters:
toWrite
- The object to get the bytes.objectMapper
- The mapper to convert the object.- Returns:
- The object as bytes.
-