You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/12/05 04:29:59 UTC

[GitHub] [dubbo-hessian-lite] lucky-xin opened a new issue #54: org.bson.types.ObjectId序列化以及反序列化问题

lucky-xin opened a new issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54


   <!-- If you need to report a security issue please visit https://github.com/apache/dubbo/security/policy -->
   
   - [x] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
   
   ### Environment
   
   * Dubbo version: 3.0.4
   * Operating System version: MAC OS Monterey
   * Java version: jdk8
   
   ### Steps to reproduce this issue
   ### 服务消费者传递org.bson.types.ObjectId到服务提供者ObjectId和消费着的ObjectId不一致
   1. 服务消费者设置一个ObjectId调用服务提供者
   2. 服务提供者拿到ObjectId然后打印
   3. 两个ObjectId不一致
    服务提供者实现代码
   ![image](https://user-images.githubusercontent.com/13815910/140744335-7f3420d8-311a-4cd9-bcfd-e46aeb342fe5.png)
   服务消费者实现代码
   ![image](https://user-images.githubusercontent.com/13815910/140744400-c189f407-85e1-496c-a916-e628ac7dc8cd.png)
   测试单元代码
   ![image](https://user-images.githubusercontent.com/13815910/140744516-4313bae6-28d4-4ded-bd4c-20cc9215e95c.png)
   [bug复现项目代码链接](https://github.com/lucky-xin/dubbo-samples)
   
   Pls. provide [GitHub address] to reproduce this issue.
   
   ### Expected Behavior
   
   期望消费者与提供者之间传递ObjectId时,序列化以及反序列化之后,ObjectId值不变
   
   ### Actual Behavior
   
   <!-- What actually happens? -->
   
   If there is an exception, please attach the exception trace:
   
   ```
   Just put your stack trace here!
   ```
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin commented on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin commented on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986411610


   嗯嗯,@zrlw 如果类定义了writeObject方法(void writeObject(ObjectOutputStream oos))应该都有该问题,影响挺大的,还辛苦你们看看了


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin edited a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin edited a comment on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986413418


   如果类定义了writeReplace方法,那么在创建JavaSerializer时会遍历类获取writeReplace方法
   ```java
    private Method _writeReplace;
   
       public JavaSerializer(Class cl, ClassLoader loader) {
           introspectWriteReplace(cl, loader);// 这里初始化_writeReplace
   
           if (_writeReplace != null)
               _writeReplace.setAccessible(true);
   }
   ```
   然后在序列化时就执行以下代码
   ```java
    @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);
   
                   //Some class would return itself for wrapReplace, which would cause infinite recursion
                   //In this case, we could write the object just like normal cases
                   if (repl != obj) {
                       out.removeRef(obj);
   
                       out.writeObject(repl);
   
                       out.replaceRef(repl, obj);
   
                       return;
                   }
               }
           } catch (RuntimeException e) {
               throw e;
           } catch (Exception e) {
               // log.log(Level.FINE, e.toString(), e);
               throw new RuntimeException(e);
           }
   
           int ref = out.writeObjectBegin(cl.getName());
   
           if (ref < -1) {
               writeObject10(obj, out);
           } else {
               if (ref == -1) {
                   writeDefinition20(out);
                   out.writeObjectBegin(cl.getName());
               }
   
               writeInstance(obj, out);
           }
       }
   ```
   因为_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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin commented on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin commented on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986406162


   那你去看看这个https://github.com/apache/dubbo-hessian-lite/issues/55还有https://github.com/apache/dubbo-hessian-lite/issues/48也是这个问题


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin edited a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin edited a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin edited a comment on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986413418


   如果类定义了writeReplace方法,那么在创建JavaSerializer时会遍历类获取writeReplace方法
   ```java
    private Method _writeReplace;
   
       public JavaSerializer(Class cl, ClassLoader loader) {
           introspectWriteReplace(cl, loader);// 这里初始化_writeReplace
   
           if (_writeReplace != null)
               _writeReplace.setAccessible(true);
   }
   ```
   然后在序列化时就执行com.alibaba.com.caucho.hessian.io.JavaSerializer#writeObject方法,代码如下
   ```java
    @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);
   
                   //Some class would return itself for wrapReplace, which would cause infinite recursion
                   //In this case, we could write the object just like normal cases
                   if (repl != obj) {
                       out.removeRef(obj);
   
                       out.writeObject(repl);
   
                       out.replaceRef(repl, obj);
   
                       return;
                   }
               }
           } catch (RuntimeException e) {
               throw e;
           } catch (Exception e) {
               // log.log(Level.FINE, e.toString(), e);
               throw new RuntimeException(e);
           }
   
           int ref = out.writeObjectBegin(cl.getName());
   
           if (ref < -1) {
               writeObject10(obj, out);
           } else {
               if (ref == -1) {
                   writeDefinition20(out);
                   out.writeObjectBegin(cl.getName());
               }
   
               writeInstance(obj, out);
           }
       }
   ```
   因为_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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin commented on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin commented on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986367232


   序列化时:
   org.bson.types.ObjectId序列化会调用org.bson.types.ObjectId#writeReplace方法实际上序列化对象为
   ![image](https://user-images.githubusercontent.com/13815910/144773817-29cf9c04-240c-4bde-b607-414ef6cbc681.png)
   反序列化时:
   ![image](https://user-images.githubusercontent.com/13815910/144774293-fa226d5e-4899-4fc0-aacf-17bde9339c27.png)
   反序列化时把org.bson.types.ObjectId.SerializationProxy反序列化为org.bson.types.ObjectId失败
   
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin edited a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin edited a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin edited a comment on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986413418


   如果类定义了writeReplace方法,那么在创建JavaSerializer时会遍历类获取writeReplace方法
   ```java
    private Method _writeReplace;
   
       public JavaSerializer(Class cl, ClassLoader loader) {
           introspectWriteReplace(cl, loader);// 这里初始化_writeReplace
   
           if (_writeReplace != null)
               _writeReplace.setAccessible(true);
   }
   ```
   然后在序列化时就执行com.alibaba.com.caucho.hessian.io.JavaSerializer#writeObject方法,代码如下
   ```java
    @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);
   
                   //Some class would return itself for wrapReplace, which would cause infinite recursion
                   //In this case, we could write the object just like normal cases
                   if (repl != obj) {
                       out.removeRef(obj);
   
                       out.writeObject(repl);
   
                       out.replaceRef(repl, obj);
   
                       return;
                   }
               }
           } catch (RuntimeException e) {
               throw e;
           } catch (Exception e) {
               // log.log(Level.FINE, e.toString(), e);
               throw new RuntimeException(e);
           }
   
           int ref = out.writeObjectBegin(cl.getName());
   
           if (ref < -1) {
               writeObject10(obj, out);
           } else {
               if (ref == -1) {
                   writeDefinition20(out);
                   out.writeObjectBegin(cl.getName());
               }
   
               writeInstance(obj, out);
           }
       }
   ```
   因为_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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] zrlw commented on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986410027


   hessian定位和Java序列化定位不同,前者追求的是高效,生成的字节流也要短,但是高效的代价是没有Java序列化可靠,而且也不如Java序列化支持的全面。


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin edited a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin edited a comment on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986367232


   序列化时:
   org.bson.types.ObjectId序列化会调用org.bson.types.ObjectId#writeReplace方法实际上序列化对象为org.bson.types.ObjectId.SerializationProxy
   ![image](https://user-images.githubusercontent.com/13815910/144773817-29cf9c04-240c-4bde-b607-414ef6cbc681.png)
   反序列化时:
   ![image](https://user-images.githubusercontent.com/13815910/144774293-fa226d5e-4899-4fc0-aacf-17bde9339c27.png)
   反序列化时把org.bson.types.ObjectId.SerializationProxy反序列化为org.bson.types.ObjectId失败
   
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin commented on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin commented on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-987588682


   这是个大坑,踩过的人才知道


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin commented on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin commented on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986407209


   那你@zrlw 去看看这个
   https://github.com/apache/dubbo-hessian-lite/issues/55
   也是这个问题,还有这个
   https://github.com/apache/dubbo-hessian-lite/issues/48
   使用标准的jdk序列化与反序列化是没有问题的


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin edited a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin edited a comment on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-987588682


   这是个大坑,踩过的人才知道,体验不好呀,我建议把它修复了吧,或者在文档做个说明,目前不支持这些序列化


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin commented on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin commented on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986372563


   反序列化时应该调用org.bson.types.ObjectId.SerializationProxy#readResolve
   ![image](https://user-images.githubusercontent.com/13815910/144775857-adfe0c4c-4142-4d78-9446-756dc7b8b659.png)
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin removed a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin removed a comment on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986406162


   那你去看看这个https://github.com/apache/dubbo-hessian-lite/issues/55还有https://github.com/apache/dubbo-hessian-lite/issues/48也是这个问题


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin commented on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin commented on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986409152






-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin edited a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin edited a comment on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-987588682


   这是个大坑,踩过的人才知道,我建议把它修复了吧,或者在文档做个说明,目前不支持这些序列化


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] zrlw commented on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986395087


   这种不符合标准序列化接口的类型自己包装一下应该就好了,hessian2作为通用工具类不可能支持所有特殊类型的序列化和反序列化


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin removed a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin removed a comment on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986409152


   如果有writeObject方法应该都有该问题,譬如jdk 9及以后版本的List.of,Map.of,Set.of...都会有这个问题


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin edited a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
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);
   
                   //Some class would return itself for wrapReplace, which would cause infinite recursion
                   //In this case, we could write the object just like normal cases
                   if (repl != obj) {
                       out.removeRef(obj);
   
                       out.writeObject(repl);
   
                       out.replaceRef(repl, obj);
   
                       return;
                   }
               }
           } catch (RuntimeException e) {
               throw e;
           } catch (Exception e) {
               // log.log(Level.FINE, e.toString(), e);
               throw new RuntimeException(e);
           }
   
           int ref = out.writeObjectBegin(cl.getName());
   
           if (ref < -1) {
               writeObject10(obj, out);
           } else {
               if (ref == -1) {
                   writeDefinition20(out);
                   out.writeObjectBegin(cl.getName());
               }
   
               writeInstance(obj, out);
           }
       }
   ```
   因为_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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin commented on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin commented on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986413418


   写错了,如果类定义了java.util.CollSer#readResolve方法,那么在创建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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin edited a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin edited a comment on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986409153


   如果有writeReplace方法应该都有该问题,譬如jdk 9及以后版本的List.of,Map.of,Set.of...创建的对象都会有这个问题


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] zrlw commented on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-987529444


   如果org.bson.types.ObjectId直接有readResolve,那么应该是支持的,但是它是内部类里面实现的,hessian为了执行高效没有去查内部类,还有你说的jdk9之类的List.of这些可能都不是hessian的菜吧,搞这些东西之后可能会把hessian的执行效率降低到java序列化一个档次。
   要完整支持序列化,可能要用java序列化而不是hessian了。


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-hessian-lite] lucky-xin removed a comment on issue #54: org.bson.types.ObjectId序列化以及反序列化问题

Posted by GitBox <gi...@apache.org>.
lucky-xin removed a comment on issue #54:
URL: https://github.com/apache/dubbo-hessian-lite/issues/54#issuecomment-986411610


   嗯嗯,@zrlw 如果类定义了writeObject方法(void writeObject(ObjectOutputStream oos))应该都有该问题,影响挺大的,还辛苦你们看看了


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org