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

io.hyperfoil.tools.horreum.converter.JsonToEventConverter Maven / Gradle / Ivy

There is a newer version: 0.15.3
Show newest version
package io.hyperfoil.tools.horreum.converter;

import java.lang.reflect.Type;

import jakarta.enterprise.context.ApplicationScoped;

import org.eclipse.microprofile.reactive.messaging.Message;

import io.smallrye.reactive.messaging.MessageConverter;
import io.smallrye.reactive.messaging.amqp.IncomingAmqpMetadata;
import io.vertx.core.json.JsonObject;

@ApplicationScoped
public class JsonToEventConverter implements MessageConverter {
    @Override
    public boolean canConvert(Message in, Type target) {
        return in.getMetadata(IncomingAmqpMetadata.class)
                .map(meta -> meta.getContentType().equals("application/json") && target instanceof Class)
                .orElse(false);
    }

    @Override
    public Message convert(Message in, Type target) {
        return in.withPayload(((JsonObject) in.getPayload()).mapTo((Class) target));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy