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

com.hframework.common.springext.converter.DateJsonSerializer Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.hframework.common.springext.converter;

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

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

/**
 * Created by zhangquanhong on 2016/6/22.
 */
public class DateJsonSerializer extends JsonSerializer {
    public static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Override
    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
        if(date == null) {
            jsonGenerator.writeString("");
            return ;
        }
        jsonGenerator.writeString(format.format(date));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy