All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.wycst.wast.json.temporal.TemporalLocalDateTimeSerializer Maven / Gradle / Ivy

Go to download

Wast is a high-performance Java toolset library package that includes JSON, YAML, CSV, HttpClient, JDBC and EL engines

There is a newer version: 0.0.16
Show newest version
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(),
                "");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy