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

Spring's default TypeResolverBuilder creates a problem. #2932

Closed
2357457057 opened this issue Jun 27, 2024 · 1 comment
Closed

Spring's default TypeResolverBuilder creates a problem. #2932

2357457057 opened this issue Jun 27, 2024 · 1 comment
Labels
status: duplicate A duplicate of another issue

Comments

@2357457057
Copy link

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 27, 2024
@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 27, 2024
@mp911de
Copy link
Member

mp911de commented Jun 27, 2024

This is a duplicate of #2697

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants