package top.imwork.commons.core.config;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.jackson.JsonComponent;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

/**
 * Copyright (C), 2015-2021
 * FileName: Long2StringAdapter
 * Author(作者姓名):   jiangxiaowei
 * CreateDate(创建时间):     2021/8/2 15:36
 * UpdateDate(修改时间):     2021/8/2 15:36
 * Description(功能描述):    Long2StringAdapter
 * Since(版本号)  1.0.0
 * History:
 */
@JsonComponent
public class Long2StringAdapter {
    @Bean
    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        SimpleModule module = new SimpleModule();
        module.addSerializer(Long.class, ToStringSerializer.instance);
        objectMapper.registerModule(module);
        return objectMapper;
    }
}
