package com.sikey.wa04.common.dto.deserializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.sikey.wa04.common.enums.MessageType;

import java.io.IOException;

public class MessageTypeSerializer extends JsonSerializer<MessageType> implements Serializer {

    @Override
    public void registerModule(ObjectMapper objectMapper) {
        SimpleModule module = new SimpleModule();
        module.addSerializer(MessageType.class, this);
        objectMapper.registerModule(module);
    }

    @Override
    public void serialize(MessageType value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeObject(value.getValue());
    }
}
