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

matrix.module.based.serializer.DateTimeSerializer Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package matrix.module.based.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 序列化Date类型为string
 *
 * @author wangcheng
 */
public class DateTimeSerializer extends JsonSerializer {

    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public void serialize(Date date, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        String format = FORMAT.format(date);
        gen.writeString("1000-01-01 00:00:00".equals(format) ? "" : format);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy