All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.reactivecommons.async.commons.converters.json.CloudEventBuilderExt Maven / Gradle / Ivy

There is a newer version: 5.2.2
Show newest version
package org.reactivecommons.async.commons.converters.json;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.cloudevents.CloudEvent;
import io.cloudevents.CloudEventData;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;

import java.util.Objects;

@UtilityClass
public class CloudEventBuilderExt {
    private static final ObjectMapper mapper = new ObjectMapper();

    @SneakyThrows
    public static byte[] asBytes(Object object) {
        return mapper.writeValueAsBytes(object);
    }

    public static CloudEventData asCloudEventData(Object object) {
        return () -> asBytes(object);
    }

    @SneakyThrows
    public static  T fromCloudEventData(CloudEvent cloudEvent, Class classValue) {
        return mapper.readValue(Objects.requireNonNull(cloudEvent.getData()).toBytes(), classValue);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy