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

[QUESTION] 是否有一种方式,能够在反序列化的前后做一些拦截 #3326

Open
citytianya opened this issue Feb 10, 2025 · 0 comments
Labels
question Further information is requested
Milestone

Comments

@citytianya
Copy link

citytianya commented Feb 10, 2025

请描述您的问题

询问有关本项目的使用和其他方面的相关问题。

目前反序列化时,在com.alibaba.fastjson2.util.TypeUtils#loadClass里,目前是有Thread.currentThread().getContextClassLoader()这个类加载器来加载类。但是,我目前遇到了一个问题,不能使用这个类加载器,ContextClassLoader在业务里被用来加载另外一个隔离scope的类,而当每次都加载不到的时候,会产生严重的性能问题。

fastjson2反序列化的时候,会在com.alibaba.fastjson2.reader.ObjectReaderProvider#checkAutoType里调用一次loadClass,但每次都加载不到,因为这个业务自定义classLoader的问题,出现高性能延迟。

所以希望能只在反序列化前后,把这个自定义的ContextClassLoader替换掉。

除了cglib之外,fastjson2内部是否提供了这样的机制?

整个我需要做类似下面这个事情,但我希望一次性搞定。

ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try{
   Thread.currentThread().setContextClassLoader(null);
   JSON.parseObject(json);   
}finally{
   Thread.currentThread().setContextClassLoader(contextClassLoader );
}
@citytianya citytianya added the question Further information is requested label Feb 10, 2025
@wenshao wenshao added this to the 2.0.57 milestone Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants