package cn.axzo.msg.center.domain.utils;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;

/**
 * @author yanglin
 */
@Slf4j
@MappedTypes({Object.class})
@MappedJdbcTypes(JdbcType.VARCHAR)
@RequiredArgsConstructor
public class IgnorePropsJsonTypeHandler extends AbstractJsonTypeHandler<Object> {

    private final Class<?> type;

    @Override
    protected Object parse(String json) {
        if (StringUtils.isBlank(json))
            return null;
        return JSON.parseObject(json, type);
    }

    @Override
    protected String toJson(Object obj) {
        return JSON.toJSONString(obj);
    }

}