Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

autoType is not support. org.springframework.security.oauth2.common.DefaultOAuth2AccessToken #1962

@glpyh

Description

@glpyh

保存jwt的token到redis中,报以下错误,尝试了开启autotype,还是无解,麻烦大家帮看一下。
error:autoType is not support. org.springframework.security.oauth2.common.DefaultOAuth2AccessToken
RedisCodec:

 @Bean
    public RedisCodec<String, Object> redisCodec() {
        FastJsonCodec fastJsonCodec=new FastJsonCodec<>(Object.class);
        // 全局开启AutoType,不建议使用
//         ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
        // 建议使用这种方式,小范围指定白名单
        ParserConfig.getGlobalInstance().addAccept("org.springframework.security.oauth2.common.");

        return fastJsonCodec;
    }

FastJsonCodec :

 @Override
    public T decodeValue(ByteBuffer bytes) {
        byte[] bytesArray = new byte[bytes.remaining()];
        bytes.get(bytesArray);
        if (bytesArray == null || bytesArray.length <= 0) {
            return null;
        }else{
            try {
                String str = new String(bytesArray,  IOUtils.UTF8);
                return JSON.parseObject(str, clazz);
            } catch (Exception e) {
                log.error("decodeValue error:{}",e.getMessage());
                return null;
            }
        }

    }
  @Override
    public ByteBuffer encodeValue(T t) {
        if (t == null) {
            return ByteBuffer.wrap(new byte[0]);
        }else{
            try {
                return ByteBuffer.wrap(JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(IOUtils.UTF8));
            } catch (Exception e) {
                throw new SerializationException("Could not serialize: " + e.getMessage(), e);
            }
        }

    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions