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

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

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

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import matrix.boot.common.exception.ServiceException;
import matrix.boot.common.utils.DateUtil;
import matrix.boot.common.utils.StringUtil;

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

/**
 * 反序列化Date类型为string
 *
 * @author wangcheng
 */
public class DateTimeDeserializer extends JsonDeserializer {

    @Override
    public Date deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
        String date = jsonParser.getText();
        if (StringUtil.isEmpty(date)) {
            return null;
        }
        try {
            return DateUtil.parse(DateUtil.STANDARD_FORMATTER, date);
        } catch (Exception e) {
            throw new ServiceException(e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy