package com.ruoyi.ems.handler.json;

import java.io.IOException;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import cn.hutool.core.codec.Base64;

public class CustomBaseSerializer extends JsonDeserializer<String> {

    @Override
    public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        final String base64Str = p.getCodec().readValue(p, new TypeReference<String>() {
        });
        if (StringUtils.isNotEmpty(base64Str)) {
            return Base64.decodeStr(base64Str);
        }
        return "";
    }
}
