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

dev.struchkov.godfather.main.domain.jackson.TelegramPayloadSerializer Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
package dev.struchkov.godfather.main.domain.jackson;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import dev.struchkov.haiti.utils.container.ContextKey;

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

public class TelegramPayloadSerializer extends StdSerializer> {

    public TelegramPayloadSerializer() {
        this(null);
    }

    public TelegramPayloadSerializer(Class> t) {
        super(t);
    }

    @Override
    public void serialize(Map value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeStartObject();

        for (Map.Entry entry : value.entrySet()) {
            ContextKey key = entry.getKey();
            String keyString = key.getType().getName() + "@" + key.getValue();
            Object objectValue = entry.getValue();

            gen.writeObjectField(keyString, objectValue);
        }

        gen.writeEndObject();
    }


}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy