39 lines
1.0 KiB
Java
39 lines
1.0 KiB
Java
|
|
package com.njcn.influx.utils;
|
||
|
|
|
||
|
|
import cn.hutool.core.date.DatePattern;
|
||
|
|
import cn.hutool.core.date.DateUtil;
|
||
|
|
import com.fasterxml.jackson.core.JsonParser;
|
||
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||
|
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||
|
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||
|
|
import org.springframework.stereotype.Component;
|
||
|
|
|
||
|
|
import java.io.IOException;
|
||
|
|
import java.time.Instant;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author hongawen
|
||
|
|
* @version 1.0.0
|
||
|
|
* @date 2023年07月24日 13:33
|
||
|
|
*/
|
||
|
|
@Component
|
||
|
|
public class InstantDateDeserializer extends StdDeserializer<Instant> {
|
||
|
|
|
||
|
|
|
||
|
|
public InstantDateDeserializer() {
|
||
|
|
this(null);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
protected InstantDateDeserializer(Class<?> vc) {
|
||
|
|
super(vc);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||
|
|
String text = p.getValueAsString();
|
||
|
|
return InstantUtil.dateToInstant(DateUtil.parse(text,DatePattern.NORM_DATETIME_PATTERN));
|
||
|
|
}
|
||
|
|
}
|