Skip to content

Spring's default TypeResolverBuilder creates a problem. #2932

Closed as not planned
@2357457057

Description

@2357457057

Here's a code example of the problem I ran into.
I use the RedisSerializer serialize a Object,but ican't deserialize it.

  public static void main(String[] args) {
       GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer();
        serializer.configure(objectMapper -> objectMapper.registerModule(new JavaTimeModule()));

        String[] a = new String[]{"1", "2"};
        byte[] serialize = serializer.serialize(a);

        System.out.println(new String(serialize, StandardCharsets.UTF_8));
        try {
            System.out.println(serializer.deserialize(serialize));
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }

        //unmodifiableList
        List<String> collect = Arrays.stream(a).toList();
        serialize = serializer.serialize(collect);
        System.out.println(new String(serialize, StandardCharsets.UTF_8));
        try {
            System.out.println(serializer.deserialize(serialize));
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }

        //ArrayList
        collect = Arrays.stream(a).collect(Collectors.toList());
        serialize = serializer.serialize(collect);
        System.out.println(new String(serialize, StandardCharsets.UTF_8));
        try {
            System.out.println(serializer.deserialize(serialize));
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

Executing the above code gives the following result:

  1. Array deserialization failed
  2. unmodifiableList deserialization failed
  3. ArrayList was deserialized successfully

After debugging, I found that the code in the figure is causing this problem. It looks like it is filtering out some basic types, but why should it be written like this, so it is not causing some problems now? Can anyone help with that? Thank you very much

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions