diff --git a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/jsonserializer/FastJson2JsonRedisSerializer.java b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/jsonserializer/FastJson2JsonRedisSerializer.java index a5780c4b..427c11b3 100644 --- a/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/jsonserializer/FastJson2JsonRedisSerializer.java +++ b/opsli-plugins/opsli-plugins-redis/src/main/java/org/opsli/plugins/redis/jsonserializer/FastJson2JsonRedisSerializer.java @@ -1,5 +1,7 @@ package org.opsli.plugins.redis.jsonserializer; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.support.config.FastJsonConfig; import lombok.extern.slf4j.Slf4j; @@ -13,12 +15,15 @@ import java.nio.charset.StandardCharsets; * FastJson2JsonRedisSerializer * Redis使用FastJson序列化 * - * @author Parker + * @author 周鹏程 * @date 2021年6月1日13:57:02 */ @Slf4j public class FastJson2JsonRedisSerializer implements RedisSerializer { + /** 双引号 */ + private static final String SYMBOL = "\""; + public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; private FastJsonConfig fastJsonConfig = new FastJsonConfig(); private final Class type; @@ -61,18 +66,36 @@ public class FastJson2JsonRedisSerializer implements RedisSerializer { return null; } try { - return cast(JSON.parseObject( + String sourceStr = new String(bytes); + Object parse = JSON.parseObject( bytes, fastJsonConfig.getCharset(), type, fastJsonConfig.getParserConfig(), fastJsonConfig.getParseProcess(), JSON.DEFAULT_PARSER_FEATURE, - fastJsonConfig.getFeatures() - )); + fastJsonConfig.getFeatures()); + + // 验证字符串 + String verifyStr = sourceStr; + boolean wrap = StrUtil.isWrap(verifyStr, SYMBOL); + if(wrap){ + // 去掉前后缀 + verifyStr = StrUtil.unWrap(verifyStr, SYMBOL, SYMBOL); + } + + // 如果是数字 + if(NumberUtil.isNumber(verifyStr)){ + // 比较位数是否相同 如果不同 则补位 + String currStr = parse.toString(); + if(!StrUtil.equals(verifyStr, currStr)){ + parse = verifyStr; + } + } + + return cast(parse); } catch (Exception ex) { - // 容错处理 - log.error(ex.getMessage(), ex); + //log.error(ex.getMessage(), ex); String str = new String(bytes, DEFAULT_CHARSET); return cast(str); }