diff --git a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectInput.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectInput.java index e8307748deb..834a4ca5f48 100644 --- a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectInput.java +++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectInput.java @@ -17,7 +17,7 @@ package org.apache.dubbo.common.serialize.protostuff; -import io.protostuff.GraphIOUtil; +import io.protostuff.ProtobufIOUtil; import io.protostuff.Schema; import io.protostuff.runtime.RuntimeSchema; import java.io.DataInputStream; @@ -61,12 +61,12 @@ public Object readObject() throws IOException, ClassNotFoundException { if (WrapperUtils.needWrapper(clazz)) { Schema schema = RuntimeSchema.getSchema(Wrapper.class); Wrapper wrapper = schema.newMessage(); - GraphIOUtil.mergeFrom(bytes, wrapper, schema); + ProtobufIOUtil.mergeFrom(bytes, wrapper, schema); result = wrapper.getData(); } else { Schema schema = RuntimeSchema.getSchema(clazz); result = schema.newMessage(); - GraphIOUtil.mergeFrom(bytes, result, schema); + ProtobufIOUtil.mergeFrom(bytes, result, schema); } return result; diff --git a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java index ab94d3ba8df..5657adbc254 100644 --- a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java +++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java @@ -17,7 +17,7 @@ package org.apache.dubbo.common.serialize.protostuff; -import io.protostuff.GraphIOUtil; +import io.protostuff.ProtobufIOUtil; import io.protostuff.LinkedBuffer; import io.protostuff.Schema; import io.protostuff.runtime.RuntimeSchema; @@ -50,11 +50,11 @@ public void writeObject(Object obj) throws IOException { if (obj == null || WrapperUtils.needWrapper(obj)) { Schema schema = RuntimeSchema.getSchema(Wrapper.class); Wrapper wrapper = new Wrapper(obj); - bytes = GraphIOUtil.toByteArray(wrapper, schema, buffer); + bytes = ProtobufIOUtil.toByteArray(wrapper, schema, buffer); classNameBytes = Wrapper.class.getName().getBytes(); } else { Schema schema = RuntimeSchema.getSchema(obj.getClass()); - bytes = GraphIOUtil.toByteArray(obj, schema, buffer); + bytes = ProtobufIOUtil.toByteArray(obj, schema, buffer); classNameBytes = obj.getClass().getName().getBytes(); } } finally { diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutputTest.java b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutputTest.java index 52397920f0f..37347cdad40 100644 --- a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutputTest.java +++ b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutputTest.java @@ -23,9 +23,13 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.Serializable; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.Date; +import java.util.List; +import org.apache.dubbo.common.serialize.model.SerializablePerson; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -90,9 +94,58 @@ public void testSerializeDate() throws IOException, ClassNotFoundException { assertThat(serializedTime, is(originTime)); } + @Test + public void testListObject() throws IOException, ClassNotFoundException { + List list = new ArrayList(); + list.add(new SerializablePerson()); + list.add(new SerializablePerson()); + list.add(new SerializablePerson()); + SerializablePersonList personList = new SerializablePersonList(list); + this.protostuffObjectOutput.writeObject(personList); + this.flushToInput(); + + SerializablePersonList serializedTime = protostuffObjectInput.readObject(SerializablePersonList.class); + assertThat(serializedTime, is(personList)); + } + private void flushToInput() throws IOException { this.protostuffObjectOutput.flushBuffer(); this.byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); this.protostuffObjectInput = new ProtostuffObjectInput(byteArrayInputStream); } + + private class SerializablePersonList implements Serializable { + private static final long serialVersionUID = 1L; + + public List personList; + + public SerializablePersonList() {} + + public SerializablePersonList(List list) { + this.personList = list; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + + SerializablePersonList list = (SerializablePersonList) obj; + if (list.personList == null && this.personList == null) + return true; + if (list.personList == null || this.personList == null) + return false; + if (list.personList.size() != this.personList.size()) + return false; + for (int i =0; i < this.personList.size(); i++) { + if (!this.personList.get(i).equals(list.personList.get(i))) + return false; + } + return true; + } + } }