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

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

There is a newer version: 2.1.10
Show newest version
package matrix.boot.based.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import matrix.boot.common.utils.DateUtil;

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

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

    @Override
    public void serialize(Date date, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (date != null) {
            gen.writeString(DateUtil.format(date, DateUtil.STANDARD_FORMATTER));
        } else {
            gen.writeNull();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy