package com.yeejoin.amos.patrol.dao.entity;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
import java.sql.Time;

public class TimeDeserializer extends JsonDeserializer<Time> {
    @Override
    public Time deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        if (p.getCurrentToken().isNumeric()) {
            long timeInMillis = p.getLongValue();
            return new Time(timeInMillis);
        } else if (p.getCurrentToken().isScalarValue()) {
            String timeStr = p.getText();
            if (timeStr != null && !timeStr.isEmpty()) {
                return Time.valueOf(timeStr);
            }
        }
        return null;
    }
}