|
6 | 6 | import com.alibaba.fastjson2.writer.ObjectWriter;
|
7 | 7 | import com.alibaba.fastjson2.writer.ObjectWriterProvider;
|
8 | 8 | import org.junit.jupiter.api.Test;
|
| 9 | +import org.springframework.cglib.proxy.Enhancer; |
| 10 | +import org.springframework.cglib.proxy.MethodInterceptor; |
| 11 | +import org.springframework.cglib.proxy.MethodProxy; |
9 | 12 |
|
| 13 | +import java.lang.reflect.Method; |
10 | 14 | import java.lang.reflect.Type;
|
| 15 | +import java.util.concurrent.TimeUnit; |
11 | 16 |
|
12 | 17 | import static org.junit.jupiter.api.Assertions.*;
|
13 | 18 |
|
@@ -131,9 +136,28 @@ public void testWriter2() {
|
131 | 136 | assertSame(writer1, JSON.registerIfAbsent(Bean.class, writer, false));
|
132 | 137 | }
|
133 | 138 |
|
| 139 | + @Test |
| 140 | + public void testWriterProxy() throws InterruptedException { |
| 141 | + Enhancer enhancer = new Enhancer(); |
| 142 | + enhancer.setSuperclass(Bean.class); |
| 143 | + enhancer.setCallback(new BeanMethodInterceptor()); |
| 144 | + Object proxy1 = enhancer.create(); |
| 145 | + JSON.toJSONString(proxy1); |
| 146 | + JSON.toJSONString(proxy1); |
| 147 | + TimeUnit.MINUTES.sleep(60); |
| 148 | + } |
| 149 | + |
134 | 150 | public static class Bean {
|
135 | 151 | }
|
136 | 152 |
|
| 153 | + public static class BeanMethodInterceptor implements MethodInterceptor { |
| 154 | + |
| 155 | + @Override |
| 156 | + public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { |
| 157 | + return methodProxy.invokeSuper(o, objects); |
| 158 | + } |
| 159 | + } |
| 160 | + |
137 | 161 | public static class BeanWriter
|
138 | 162 | implements ObjectWriter {
|
139 | 163 | @Override
|
|
0 commit comments