sunhk commented on issue #10386:
URL: https://github.com/apache/dubbo/issues/10386#issuecomment-1201942766

   
是有点别扭,但官方文档https://docs.oracle.com/javase/8/docs/platform/serialization/spec/output.html#a5324
 
并未强调writeReplace的返回值需实现序列化接口,事实上SerializationProxy是否实现序列化接口也并不影响com.alibaba.com.caucho.hessian.io.JavaSerializer的逻辑
   java原生的ObjectOutputStream与ObjectInputStream也可正常运行
   ```
   @Test
       public void testObjectSerialization() throws IOException, 
ClassNotFoundException {
           // given
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
           ObjectOutputStream oos = new ObjectOutputStream(baos);
           ObjectId objectId = new ObjectId("5f8f4fcf27516f05e7eae5be");
   
           // when
           oos.writeObject(objectId);
   
           // then
           assertTrue(new 
String(baos.toByteArray()).contains("org.bson.types.ObjectId$SerializationProxy"));
           assertArrayEquals(new byte[] {-84, -19, 0, 5, 115, 114, 0, 42, 111, 
114, 103, 46, 98, 115, 111, 110, 46, 116, 121, 112, 101, 115,
                           46, 79, 98, 106, 101, 99, 116, 73, 100, 36, 83, 101, 
114, 105, 97, 108, 105, 122, 97, 116, 105, 111, 110, 80, 114,
                           111, 120, 121, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 1, 91, 
0, 5, 98, 121, 116, 101, 115, 116, 0, 2, 91, 66, 120, 112, 117,
                           114, 0, 2, 91, 66, -84, -13, 23, -8, 6, 8, 84, -32, 
2, 0, 0, 120, 112, 0, 0, 0, 12, 95, -113, 79, -49, 39, 81, 111,
                           5, -25, -22, -27, -66},
                   baos.toByteArray());
   
           // when
           ByteArrayInputStream bais = new 
ByteArrayInputStream(baos.toByteArray());
           ObjectInputStream ois = new ObjectInputStream(bais);
           ObjectId deserializedObjectId = (ObjectId) ois.readObject();
   
           // then
           assertEquals(objectId, deserializedObjectId);
       }
   ``` 


-- 
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