相关文章推荐

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 com.alibaba.fastjson2.reader.ObjectReaderImplObject中 Thread.currentThread().getContextClassLoader()为null 导致空指针 #1534 com.alibaba.fastjson2.reader.ObjectReaderImplObject中 Thread.currentThread().getContextClassLoader()为null 导致空指针 #1534 lyy12332133 opened this issue Jun 6, 2023 · 10 comments

com.alibaba.fastjson2.reader.ObjectReaderImplObject中 Thread.currentThread().getContextClassLoader()为null 导致空指针

请填写以下信息:

  • OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
  • JDK信息: [e.g.:Openjdk 1.8.0_312]
  • 版本信息:[e.g.:Fastjson2 2.0.33]
  • [BUG] com.alibaba.fastjson2.reader.ObjectReaderImplObject中 Thread.currentThread().getContextClassLoader()为null 导致空指针 Jun 6, 2023 private SpeechRecognizer speechRecognizer;

    抱歉,没法给测试用例,使用微软asr的sdk回调函数里面获取的Thread.currentThread().getContextClassLoader()就是null。
    之前使用fastjson:1.2.83没有这个问题,升级到2.0.33后存在这个问题。

    `package com.alibaba.fastjson.support.spring;

    import com.alibaba.fastjson.JSON;
    import com.alibaba.fastjson.support.config.FastJsonConfig;
    import org.springframework.data.redis.serializer.RedisSerializer;
    import org.springframework.data.redis.serializer.SerializationException;

    Fastjson for Spring Data Redis Serializer.

    public class FastJsonRedisSerializer
    implements RedisSerializer {
    private final Class type;
    private FastJsonConfig fastJsonConfig = new FastJsonConfig();

    public FastJsonRedisSerializer(Class type) {
    this.type = type;

    public FastJsonConfig getFastJsonConfig() {
    return fastJsonConfig;

    public void setFastJsonConfig(FastJsonConfig fastJsonConfig) {
    this.fastJsonConfig = fastJsonConfig;

    @OverRide
    public byte[] serialize(T type) throws SerializationException {
    if (type == null) {
    return new byte[0];
    try {
    return JSON.toJSONBytes(type, fastJsonConfig.getSerializeFilters(), fastJsonConfig.getSerializerFeatures());
    } catch (Exception ex) {
    throw new SerializationException("Could not serialize: " + ex.getMessage(), ex);

    @OverRide
    public T deserialize(byte[] bytes) throws SerializationException {
    if (bytes == null || bytes.length == 0) {
    return null;
    try {
    return JSON.parseObject(bytes, type, fastJsonConfig.getFeatures());
    } catch (Exception ex) {
    throw new SerializationException("Could not deserialize: " + ex.getMessage(), ex);

    redis用到了fastjson的序列化,反序列化时候报错了。

    `package com.alibaba.fastjson.support.spring;

    import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.support.config.FastJsonConfig; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.SerializationException;

  • Fastjson for Spring Data Redis Serializer.
  • Compatible fastjson 1.2.x
  • @author lihengming
  • @author Victor.Zxy
  • @see RedisSerializer
  • @SInCE 2.0.2
    public class FastJsonRedisSerializer
    implements RedisSerializer {
    private final Class type;
    private FastJsonConfig fastJsonConfig = new FastJsonConfig();
    public FastJsonRedisSerializer(Class type) {
    this.type = type;
    public FastJsonConfig getFastJsonConfig() {
    return fastJsonConfig;
    public void setFastJsonConfig(FastJsonConfig fastJsonConfig) {
    this.fastJsonConfig = fastJsonConfig;
    @OverRide
    public byte[] serialize(T type) throws SerializationException {
    if (type == null) {
    return new byte[0];
    try {
    return JSON.toJSONBytes(type, fastJsonConfig.getSerializeFilters(), fastJsonConfig.getSerializerFeatures());
    } catch (Exception ex) {
    throw new SerializationException("Could not serialize: " + ex.getMessage(), ex);
    @OverRide
    public T deserialize(byte[] bytes) throws SerializationException {
    if (bytes == null || bytes.length == 0) {
    return null;
    try {
    return JSON.parseObject(bytes, type, fastJsonConfig.getFeatures());
    } catch (Exception ex) {
    throw new SerializationException("Could not deserialize: " + ex.getMessage(), ex);

    fastjson2-2.0.34-SNAPSHOT.zip

    redis用到了fastjson的序列化,反序列化时候报错了。

    麻烦用这个试试,

  •  
    推荐文章