io.github.wycst.wast.json.temporal.TemporalLocalDateTimeSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wast Show documentation
Show all versions of wast Show documentation
Wast is a high-performance Java toolset library package that includes JSON, YAML, CSV, HttpClient, JDBC and EL engines
package io.github.wycst.wast.json.temporal;
import io.github.wycst.wast.common.beans.GregorianDate;
import io.github.wycst.wast.json.JSONConfig;
import io.github.wycst.wast.json.JSONTemporalSerializer;
import io.github.wycst.wast.json.JSONWriter;
import io.github.wycst.wast.json.annotations.JsonProperty;
import java.time.LocalDateTime;
/**
* LocalDateTime序列化
*
* @Author: wangy
* @Date: 2022/8/13 15:06
* @Description:
* @see GregorianDate
* @see io.github.wycst.wast.common.beans.DateTemplate
*/
public class TemporalLocalDateTimeSerializer extends JSONTemporalSerializer {
public TemporalLocalDateTimeSerializer(Class> temporalClass, JsonProperty property) {
super(temporalClass, property);
}
protected void checkClass(Class> temporalClass) {
}
@Override
protected void writeTemporalWithTemplate(Object value, JSONWriter writer, JSONConfig jsonConfig) throws Exception {
LocalDateTime localDateTime = (LocalDateTime) value;
writer.write('"');
writeDate(
localDateTime.getYear(),
localDateTime.getMonthValue(),
localDateTime.getDayOfMonth(),
localDateTime.getHour(),
localDateTime.getMinute(),
localDateTime.getSecond(),
localDateTime.getNano() / 1000000, dateFormatter, writer);
writer.write('"');
}
// yyyy-MM-ddTHH:mm:ss.SSS
@Override
protected void writeDefault(Object value, JSONWriter writer, JSONConfig jsonConfig, int indent) throws Exception {
LocalDateTime localDateTime = (LocalDateTime) value;
writer.writeJSONLocalDateTime(
localDateTime.getYear(),
localDateTime.getMonthValue(),
localDateTime.getDayOfMonth(),
localDateTime.getHour(),
localDateTime.getMinute(),
localDateTime.getSecond(),
localDateTime.getNano(),
"");
}
}