fix Set Serialize data lost (#2)
* fix Set Vector Serialize data lost https://github.com/apache/incubator-dubbo/issues/2069 https://github.com/apache/incubator-dubbo/issues/146
* update .travis.yml
* update
* update test
* update test
* update test
* change travis jdk version
diff --git a/.codecov.yml b/.codecov.yml
index 3d04ce5..ed2bdd0 100644
--- a/.codecov.yml
+++ b/.codecov.yml
@@ -3,8 +3,4 @@
# pull-requests only
patch:
default:
- threshold: 0.1%
-ignore:
- - "dubbo-demo/.*"
- - "dubbo-common/src/main/java/com/alibaba/dubbo/common/json/*.java" # internal JSON impl is deprecate, ignore test coverage for them
- - "dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/AnnotationBean.java" # Deprecated
\ No newline at end of file
+ threshold: 0.1%
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index facb5b9..53aa8ad 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,11 +2,13 @@
sudo: false # faster builds
jdk:
+ - oraclejdk10
- oraclejdk9
- oraclejdk8
+ - openjdk7
script:
- - travis_wait 30 ./mvnw clean package
+ - mvn clean package
after_success:
- - bash <(curl -s https://codecov.io/bash)
+ - bash <(curl -s https://codecov.io/bash)
\ No newline at end of file
diff --git a/README.md b/README.md
index 5598f8b..5f0e48b 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,7 @@
-Hessian Lite(Alibaba embed version)
\ No newline at end of file
+Hessian Lite(Alibaba embed version)
+
+[![Build Status](https://travis-ci.org/dubbo/hessian-lite.svg?branch=master)](https://travis-ci.org/dubbo/hessian-lite)
+[![codecov](https://codecov.io/gh/dubbo/hessian-lite/branch/master/graph/badge.svg)](https://codecov.io/gh/dubbo/hessian-lite)
+[![Gitter](https://badges.gitter.im/alibaba/dubbo.svg)](https://gitter.im/alibaba/dubbo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
+![license](https://img.shields.io/github/license/alibaba/dubbo.svg)
+![maven](https://img.shields.io/maven-central/v/com.alibaba/hessian-lite.svg)
diff --git a/pom.xml b/pom.xml
index f3fd53e..4fc3c01 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,8 +60,8 @@
<version>3.7.0</version>
<configuration>
<compilerArgument>-proc:none</compilerArgument>
- <source>1.8</source>
- <target>1.8</target>
+ <source>1.7</source>
+ <target>1.7</target>
</configuration>
</plugin>
</plugins>
diff --git a/src/main/java/com/alibaba/com/caucho/hessian/io/CollectionDeserializer.java b/src/main/java/com/alibaba/com/caucho/hessian/io/CollectionDeserializer.java
index 1d3bc89..1347aa6 100644
--- a/src/main/java/com/alibaba/com/caucho/hessian/io/CollectionDeserializer.java
+++ b/src/main/java/com/alibaba/com/caucho/hessian/io/CollectionDeserializer.java
@@ -75,7 +75,7 @@
@Override
public Object readList(AbstractHessianInput in, int length)
throws IOException {
- return readList(in, length, null);
+ return readList(in, length, _type);
}
@Override
diff --git a/src/main/java/com/alibaba/com/caucho/hessian/io/CollectionSerializer.java b/src/main/java/com/alibaba/com/caucho/hessian/io/CollectionSerializer.java
index 7ede5af..abc92d4 100644
--- a/src/main/java/com/alibaba/com/caucho/hessian/io/CollectionSerializer.java
+++ b/src/main/java/com/alibaba/com/caucho/hessian/io/CollectionSerializer.java
@@ -83,14 +83,7 @@
Collection list = (Collection) obj;
Class cl = obj.getClass();
- boolean hasEnd;
-
- if (cl.equals(ArrayList.class)
- || !_sendJavaType
- || !Serializable.class.isAssignableFrom(cl))
- hasEnd = out.writeListBegin(list.size(), null);
- else
- hasEnd = out.writeListBegin(list.size(), obj.getClass().getName());
+ boolean hasEnd = out.writeListBegin(list.size(), obj.getClass().getName());
Iterator iter = list.iterator();
while (iter.hasNext()) {
diff --git a/src/main/java/com/alibaba/com/caucho/hessian/io/HessianInput.java b/src/main/java/com/alibaba/com/caucho/hessian/io/HessianInput.java
index 417b756..ffc1732 100644
--- a/src/main/java/com/alibaba/com/caucho/hessian/io/HessianInput.java
+++ b/src/main/java/com/alibaba/com/caucho/hessian/io/HessianInput.java
@@ -56,7 +56,9 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* Input stream for Hessian requests.
@@ -1170,8 +1172,8 @@
if (List.class != reader.getType() && List.class.isAssignableFrom(reader.getType()))
return reader.readList(this, length, valueType ? expectedTypes.get(0) : null);
-
- reader = _serializerFactory.getDeserializer(List.class);
+ Class clazz = type.equals(HashSet.class.getName()) ? Set.class : List.class;
+ reader = _serializerFactory.getDeserializer(clazz);
Object v = reader.readList(this, length, valueType ? expectedTypes.get(0) : null);
diff --git a/src/test/java/com/alibaba/com/caucho/hessian/io/CollectionSerializerTest.java b/src/test/java/com/alibaba/com/caucho/hessian/io/CollectionSerializerTest.java
new file mode 100644
index 0000000..0b20240
--- /dev/null
+++ b/src/test/java/com/alibaba/com/caucho/hessian/io/CollectionSerializerTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.alibaba.com.caucho.hessian.io;
+
+import com.alibaba.com.caucho.hessian.io.base.SerializeTestBase;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+public class CollectionSerializerTest extends SerializeTestBase {
+ @Test
+ public void testSetSerializer() throws Exception {
+
+ Set set = new HashSet();
+ set.add(1111);
+ set.add(2222);
+
+ Set deserialize = baseHessianSerialize(set);
+ Assert.assertTrue(deserialize.equals(set));
+ }
+
+ @Test
+ public void testListSerializer() throws Exception {
+
+ List<Integer> list = new LinkedList<>();
+ list.add(1111);
+ list.add(2222);
+
+ List deserialize = baseHessianSerialize(list);
+ Assert.assertTrue(deserialize.equals(list));
+ }
+
+
+ @Test
+ public void testVectorSerializer() throws Exception {
+
+ Vector vector = new Vector();
+ vector.add(1111);
+ vector.add(2222);
+
+ List deserialize = baseHessianSerialize(vector);
+ Assert.assertTrue(deserialize.equals(vector));
+ }
+}