package com.xueyi.common.core.utils.time;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.xueyi.common.core.utils.DateUtil;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeParseException;

/**
 * @author yk
 * @description
 * @date 2023-08-26 16:05
 */
public class LocalDatetimeDeserializer extends JsonDeserializer<LocalDateTime> {

    @Override
    public LocalDateTime deserialize(JsonParser p, DeserializationContext ctx)
            throws IOException {
        String str = p.getText();
        try {
            return LocalDateTime.parse(str, DateUtil.DEFAULT_DATETIME_PATTERN);
        } catch (DateTimeParseException e) {
            System.err.println(e);
            return null;
        }
    }
}
