lucky-xin edited a comment on issue #54:
URL: 
https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986413418


   写错了,如果类定义了writeReplace方法,那么在创建JavaSerializer时会遍历类获取writeReplace方法
   ```
    private Method _writeReplace;
   
       public JavaSerializer(Class cl, ClassLoader loader) {
           introspectWriteReplace(cl, loader);// 这里初始化_writeReplace
   
           if (_writeReplace != null)
               _writeReplace.setAccessible(true);
   }
   ```
   然后在序列化时就执行以下代码
   ```
     @Override
       public void writeObject(Object obj, AbstractHessianOutput out)
               throws IOException {
           if (out.addRef(obj)) {
               return;
           }
   
           Class cl = obj.getClass();
   
           try {
               if (_writeReplace != null) {
                   Object repl;
   
                   if (_writeReplaceFactory != null)
                       repl = _writeReplace.invoke(_writeReplaceFactory, obj);
                   else
                       repl = _writeReplace.invoke(obj);
   
   }
   
   ```
   因为_writeReplace不为null,就执行writeReplace方法了


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to