Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] com.alibaba.fastjson2.JSONException: input not end, offset 65, character :, line 1, column 65, fastjson-version 2.0.53 开发环境好使,打成jar包咋也不行 #3190

Open
yang771036958 opened this issue Dec 2, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@yang771036958
Copy link

问题描述

com.alibaba.fastjson2.JSONException: input not end, offset 65, character :, line 1, column 65, fastjson-version 2.0.53

环境信息

spring boot 3.3.4、jdk21、redis7.2.5

  • OS信息: ubuntu24.04
  • JDK信息: jdk21.0.4
  • 版本信息:2.0.53

重现步骤

如何操作可以重现该问题:

传相同的ID,期间数据在redis里面没有任何改动,从redis里面查询,不同的调用方法 就会报错。

public Enterprise getEnterpriseByEnterpriseId(Long id) throws RuntimeException {
EnterpriseVO enterpriseVO = (EnterpriseVO) redisTemplate.opsForHash().get(RedisKeyConstant.REDIS_KEY_ENTERPRISE_ALL, String.valueOf(id));
if (enterpriseVO != null) {
return EnterpriseVO.convertToVO(enterpriseVO);
}

    // 从数据库拿
    Enterprise enterprise = this.baseMapper.selectById(id);
    if (enterprise != null) {
        return enterprise;
    }
    return enterprise;
}

图片

//可在此输入示例代码

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。

相关日志输出

请复制并粘贴任何相关的日志输出。

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@yang771036958 yang771036958 added the bug Something isn't working label Dec 2, 2024
@yang771036958 yang771036958 changed the title [BUG] [BUG] com.alibaba.fastjson2.JSONException: input not end, offset 65, character :, line 1, column 65, fastjson-version 2.0.53 Dec 2, 2024
@yang771036958
Copy link
Author

redis 序列化配置
@configuration
public class RedisConfig {

@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
    RedisTemplate<Object, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(redisConnectionFactory);

    // 使用 FastJSON2 的序列化器
    FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);

    // 配置序列化器
    template.setDefaultSerializer(serializer);
    template.setKeySerializer(new StringRedisSerializer());
    template.setValueSerializer(serializer);
    template.setHashKeySerializer(new StringRedisSerializer());
    template.setHashValueSerializer(serializer);
    return template;
}


/**
 * @ClassName FastJson2JsonRedisSerializer
 * @Description redis配置FastJson2为默认的序列化器
 * @Author ywy
 * @Date 2024/9/29 10:39
 */
public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> {
    private final Class<T> clazz;

    public FastJson2JsonRedisSerializer(Class<T> clazz) {
        super();
        this.clazz = clazz;
    }

    @Override
    public byte[] serialize(T t) throws SerializationException {
        return JSON.toJSONBytes(t, JSONWriter.Feature.WriteClassName);
    }

    @Override
    public T deserialize(byte[] bytes) throws SerializationException {
        return JSON.parseObject(bytes, clazz, JSONReader.Feature.SupportAutoType);
    }
}

}

@yang771036958
Copy link
Author

本地开发环境没有问题,打成jar包,无论测试环境还是生产环境,都会报错:com.alibaba.fastjson2.JSONException: input not end, offset 65, character :, line 1, column 65, fastjson-version 2.0.53 {"@type":"com.fengjun.finance.vo.EnterpriseVO","archivingStatus":1,"businessType":1,"children":[],"completionStatus":1,"enterpriseAbbreviationName":"孚日集团","enterpriseCity":"","enterpriseId":"254198923769507840","enterpriseName":"孚日集团股份有限公司","enterpriseProvince":"","enterpriseType":1,"mnemonicCode":"","parentId":"0","periodWhichBelongsEnd":"2024-12-31","periodWhichBelongsStart":"2024-01-01","reportDate":"2024-12-31","signatureAnnotator":"杨文远","taxpayerIdentificationNumber":"91370700165840155D","users":[{"@type":"com.fengjun.finance.vo.UserVO","mobile":"17611030000","nickName":"杨文远","userId":"2","userName":"17611030000"}]}

@yang771036958 yang771036958 changed the title [BUG] com.alibaba.fastjson2.JSONException: input not end, offset 65, character :, line 1, column 65, fastjson-version 2.0.53 [BUG] com.alibaba.fastjson2.JSONException: input not end, offset 65, character :, line 1, column 65, fastjson-version 2.0.53 开发环境好使,打成jar包咋也不行 Dec 2, 2024
@yang771036958
Copy link
Author

希望有一个临时的解决方案,突然发现了这个问题,也不知道是因为啥。。

@wenshao
Copy link
Member

wenshao commented Dec 3, 2024

是不是A类型写进去,使用B类型读取了?

@yang771036958
Copy link
Author

@wenshao 不是,这个问题复现了,使用最新版本 2.0.53,jdk21 用CompletableFuture的方法内部使用fastjson2就会报错,字符串莫名其妙的丢了。service 上面加@async 就不会有问题,
具体的我jdk21 开启了虚拟线程,jdk21.0.5,spring boot 3.3
图片

1 similar comment
@yang771036958
Copy link
Author

@wenshao 不是,这个问题复现了,使用最新版本 2.0.53,jdk21 用CompletableFuture的方法内部使用fastjson2就会报错,字符串莫名其妙的丢了。service 上面加@async 就不会有问题,
具体的我jdk21 开启了虚拟线程,jdk21.0.5,spring boot 3.3
图片

@yang771036958
Copy link
Author

还有就是 打成jar包,扔服务器上,CompletableFuture内会报错,开发环境 不会有问题。

@yang771036958
Copy link
Author

@wenshao
Copy link
Member

wenshao commented Dec 5, 2024

我怀疑是虚拟线程的情况下,ThreadLocal的数据重用出问题了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants