|
17 | 17 | package org.apache.dubbo.common.serialize.fastjson2; |
18 | 18 |
|
19 | 19 | import org.apache.dubbo.common.beans.factory.ScopeBeanFactory; |
| 20 | +import org.apache.dubbo.common.utils.ClassUtils; |
20 | 21 | import org.apache.dubbo.rpc.model.ApplicationModel; |
21 | 22 | import org.apache.dubbo.rpc.model.FrameworkModel; |
22 | 23 | import org.apache.dubbo.rpc.model.ModuleModel; |
23 | 24 | import org.apache.dubbo.rpc.model.ScopeModelInitializer; |
24 | 25 |
|
| 26 | +import java.util.Arrays; |
| 27 | + |
25 | 28 | public class Fastjson2ScopeModelInitializer implements ScopeModelInitializer { |
26 | 29 |
|
27 | 30 | @Override |
28 | 31 | public void initializeFrameworkModel(FrameworkModel frameworkModel) { |
29 | | - Class<?> aClass = null; |
| 32 | + boolean classExist = false; |
30 | 33 | try { |
31 | | - aClass = com.alibaba.fastjson2.JSONB.class; |
| 34 | + for (String className : Arrays.asList( |
| 35 | + "com.alibaba.fastjson2.JSONB", |
| 36 | + "com.alibaba.fastjson2.reader.ObjectReaderCreatorASM", |
| 37 | + "com.alibaba.fastjson2.writer.ObjectWriterCreatorASM", |
| 38 | + "com.alibaba.fastjson2.JSONValidator", |
| 39 | + "com.alibaba.fastjson2.JSONFactory", |
| 40 | + "com.alibaba.fastjson2.JSONWriter", |
| 41 | + "com.alibaba.fastjson2.util.TypeUtils", |
| 42 | + "com.alibaba.fastjson2.filter.ContextAutoTypeBeforeHandler")) { |
| 43 | + Class<?> aClass = |
| 44 | + ClassUtils.forName(className, Thread.currentThread().getContextClassLoader()); |
| 45 | + if (aClass == null) { |
| 46 | + throw new ClassNotFoundException(className); |
| 47 | + } |
| 48 | + } |
| 49 | + classExist = true; |
32 | 50 | } catch (Throwable ignored) { |
33 | 51 | } |
34 | 52 |
|
35 | | - if (aClass != null) { |
| 53 | + if (classExist) { |
36 | 54 | ScopeBeanFactory beanFactory = frameworkModel.getBeanFactory(); |
37 | 55 | beanFactory.registerBean(Fastjson2CreatorManager.class); |
38 | 56 | beanFactory.registerBean(Fastjson2SecurityManager.class); |
|
0 commit comments