xyz.migoo.framework.jackson.databind.LocalDateTimeSerializer Maven / Gradle / Ivy
The newest version!
package xyz.migoo.framework.jackson.databind;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneId;
/**
* LocalDateTime序列化规则
*
* 会将LocalDateTime序列化为毫秒级时间戳
*
* @author xiaomi
* Created on 2021/11/21 14:00
*/
public class LocalDateTimeSerializer extends JsonSerializer {
@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeNumber(value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy