
io.codemonastery.dropwizard.kinesis.EventObjectMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropwizard-kinesis Show documentation
Show all versions of dropwizard-kinesis Show documentation
Kinesis Integration for dropwizard
The newest version!
package io.codemonastery.dropwizard.kinesis;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Preconditions;
import javax.annotation.Nullable;
import java.nio.ByteBuffer;
public final class EventObjectMapper implements EventEncoder, EventDecoder {
private final ObjectMapper objectMapper;
private final Class klass;
public EventObjectMapper(ObjectMapper objectMapper, @Nullable Class klass) {
Preconditions.checkNotNull(objectMapper);
this.objectMapper = objectMapper;
this.klass = klass;
}
@Nullable
@Override
public E decode(ByteBuffer bytes) throws Exception {
if(klass == null){
throw new UnsupportedOperationException("cannot decode if event class was not specified");
}
return objectMapper.readValue(bytes.array(), klass);
}
@Nullable
@Override
public byte[] encode(E event) throws Exception {
return objectMapper.writeValueAsBytes(event);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy