Skip to content
Permalink
Browse files
fix Set Serialize data lost (#2)
* fix Set Vector Serialize data lost apache/dubbo#2069 apache/dubbo#146

* update .travis.yml

* update

* update test

* update test

* update test

* change travis jdk version
  • Loading branch information
lovepoem authored and jerrick-zhu committed Jul 13, 2018
1 parent 4c59eb6 commit 447d963c915340c2fdb0fa720de3ed6236263df0
Showing 8 changed files with 84 additions and 21 deletions.
@@ -3,8 +3,4 @@ coverage:
# 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
threshold: 0.1%
@@ -2,11 +2,13 @@ language: java
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)
@@ -1 +1,7 @@
Hessian Lite(Alibaba embed version)
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)
@@ -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>
@@ -75,7 +75,7 @@ public Class getType() {
@Override
public Object readList(AbstractHessianInput in, int length)
throws IOException {
return readList(in, length, null);
return readList(in, length, _type);
}

@Override
@@ -83,14 +83,7 @@ public void writeObject(Object obj, AbstractHessianOutput out)
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()) {
@@ -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 @@ public Object readObject(List<Class<?>> expectedTypes)

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

@@ -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));
}
}

0 comments on commit 447d963

Please sign in to comment.