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

序列化无法识别泛型 #848

Open
mzy2023 opened this issue Jan 6, 2024 · 3 comments
Open

序列化无法识别泛型 #848

mzy2023 opened this issue Jan 6, 2024 · 3 comments

Comments

@mzy2023
Copy link

mzy2023 commented Jan 6, 2024

image
如图序列化无法识别List中的泛型,只能拿到结果后再次序列化。
有没有更好的方式解决这个问题

@areyouok
Copy link
Collaborator

areyouok commented Jan 6, 2024

方法就是不要用json做序列化

@mzy2023
Copy link
Author

mzy2023 commented Jan 9, 2024

方法就是不要用json做序列化

有具体方案吗?

@dantefung
Copy link

方法就是不要用json做序列化

有具体方案吗?

1.使用Jackson2序列化时会记录类型信息, 但是报文会很大.
2. 编程式的方式,你可以手动创建Cache对象,并且自己指定好对应的序列化和反序列化编解码,不使用统一的json序列化,因为无法顾及到所有的情况,应该由编写的人自己来解决

可参考:

QuickConfig systemConfigCacheConfig = QuickConfig
.newBuilder("test", "system:config:")
.expire(Duration.ofSeconds(86410))
.cacheType(CacheType.REMOTE)
// 自己序列化
.valueEncoder(JacksonUtils::objectToByteArray)
// 自己反序列化
.valueDecoder((bytes)-> JacksonUtils.byteArrayToObject(bytes, new TypeReference<CacheValueHolder>() {}))
.build();
Cache<String, SystemConfigDTO> cache = cacheManager.getOrCreateCache(systemConfigCacheConfig);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants