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

com.github.vivekkothari.river.bean.MessageValue Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.github.vivekkothari.river.bean;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Map;

/**
 * @author vivek.kothari on 15/05/16.
 */
@Data
public class MessageValue {
    private String database;
    private String table;
    private Type type;

    @JsonProperty("ts")
    @JsonDeserialize(using = UnixTimestampDeserializer.class)
    private Timestamp timestamp;

    @JsonProperty("xid")
    private long commitId;

    @JsonProperty("commit")
    private boolean committed;

    private Map data;

    private Map old;

    public enum Type {
        insert, update, delete
    }

    @Slf4j
    private static class UnixTimestampDeserializer
            extends JsonDeserializer {

        @Override
        public Timestamp deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
            try {
                return new Timestamp(jsonParser.getLongValue() * 1000);
            } catch (NumberFormatException e) {
                log.warn("Unable to deserialize timestamp ", e);
                return null;
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy