You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/07/03 02:51:19 UTC

[incubator-servicecomb-java-chassis] 01/03: [SCB-703] identify void type to avoid response deserialization problem

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit cc32b00819cb3203777c99bd718b752ebf4b9cb3
Author: yaohaishi <ya...@huawei.com>
AuthorDate: Wed Jun 27 21:04:22 2018 +0800

    [SCB-703] identify void type to avoid response deserialization problem
---
 .../swagger/invocation/converter/ConverterMgr.java | 11 +++++-
 .../invocation/converter/ConverterMgrTest.java     | 44 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/converter/ConverterMgr.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/converter/ConverterMgr.java
index 3724619..94b8570 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/converter/ConverterMgr.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/converter/ConverterMgr.java
@@ -140,13 +140,22 @@ public class ConverterMgr {
   }
 
   protected Converter findAssignable(Type src, Type target) {
-    if (TypeUtils.isAssignable(src, target)) {
+    if (isAssignable(src, target)) {
       return same;
     }
 
     return null;
   }
 
+  boolean isAssignable(Type src, Type target) {
+    boolean assignable = TypeUtils.isAssignable(src, target);
+    if (!assignable) {
+      // void <--> java.lang.Void convert should be covered
+      assignable = (src == void.class || src == Void.class) && (target == void.class || target == Void.class);
+    }
+    return assignable;
+  }
+
   protected Converter findCollectionToArray(Type src, Type target) {
     if (ParameterizedType.class.isAssignableFrom(src.getClass()) && target.getClass().equals(Class.class)) {
       ParameterizedType srcType = (ParameterizedType) src;
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/ConverterMgrTest.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/ConverterMgrTest.java
new file mode 100644
index 0000000..b19fa964
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/converter/ConverterMgrTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.servicecomb.swagger.invocation.converter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ConverterMgrTest {
+  @Test
+  public void isAssignable() {
+    ConverterMgr converterMgr = new ConverterMgr();
+    // simple type
+    Assert.assertTrue(converterMgr.isAssignable(String.class, String.class));
+    Assert.assertTrue(converterMgr.isAssignable(int.class, Integer.class));
+    Assert.assertTrue(converterMgr.isAssignable(long.class, Long.class));
+    Assert.assertTrue(converterMgr.isAssignable(void.class, Void.class));
+    // simple type reverse
+    Assert.assertTrue(converterMgr.isAssignable(String.class, String.class));
+    Assert.assertTrue(converterMgr.isAssignable(Integer.class, int.class));
+    Assert.assertTrue(converterMgr.isAssignable(Long.class, long.class));
+    Assert.assertTrue(converterMgr.isAssignable(Void.class, void.class));
+    // Object type
+    Assert.assertTrue(converterMgr.isAssignable(ArrayList.class, List.class));
+    Assert.assertFalse(converterMgr.isAssignable(List.class, ArrayList.class));
+  }
+}