代码提交
This commit is contained in:
@@ -37,12 +37,12 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>influxdb-springboot-starter</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependency>-->
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.njcn.influx.utils.InstantDateDeserializer;
|
||||
import com.njcn.redis.seriallizer.RedisInstantDateDeserializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
@@ -41,7 +41,7 @@ public class RedisConfig {
|
||||
//解决Java 8 date/time type java.time.Instant not supported
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper.registerModule(new SimpleModule().addDeserializer(Instant.class, new InstantDateDeserializer()));
|
||||
objectMapper.registerModule(new SimpleModule().addDeserializer(Instant.class, new RedisInstantDateDeserializer()));
|
||||
|
||||
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.njcn.redis.seriallizer;
|
||||
|
||||
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;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Author: cdf
|
||||
* @CreateTime: 2025-07-25
|
||||
* @Description:
|
||||
*/
|
||||
@Component
|
||||
public class RedisInstantDateDeserializer extends StdDeserializer<Instant> {
|
||||
|
||||
public RedisInstantDateDeserializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
|
||||
protected RedisInstantDateDeserializer(Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
String text = p.getValueAsString();
|
||||
return DateUtil.parse(text, DatePattern.NORM_DATETIME_PATTERN).toInstant().plusMillis(TimeUnit.HOURS.toMillis(8));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user