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

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


The following commit(s) were added to refs/heads/2.8.x by this push:
     new e003e626c [SCB-2854]query parameter support primitive array (#4205)
e003e626c is described below

commit e003e626c2effd32b54dcae0b1386e3f195911a4
Author: liubao68 <[email protected]>
AuthorDate: Sat Jan 27 08:53:16 2024 +0800

    [SCB-2854]query parameter support primitive array (#4205)
---
 .../rest/codec/query/AbstractQueryCodec.java       |  5 ++
 .../client/TestDataTypesAnnotationsSchema.java     | 54 ++++++++++++++++++++++
 .../server/DataTypesAnnotationsSchema.java         | 36 +++++++++++++++
 .../springmvc/server/ProducerTestsAfterBootup.java |  4 +-
 4 files changed, 97 insertions(+), 2 deletions(-)

diff --git 
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/AbstractQueryCodec.java
 
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/AbstractQueryCodec.java
index 2817f9da8..e34d8996b 100644
--- 
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/AbstractQueryCodec.java
+++ 
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/query/AbstractQueryCodec.java
@@ -23,6 +23,7 @@ import java.util.Collections;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
 import 
org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
 
 public abstract class AbstractQueryCodec implements QueryCodec {
@@ -46,6 +47,10 @@ public abstract class AbstractQueryCodec implements 
QueryCodec {
     }
 
     if (value.getClass().isArray()) {
+      if (!(value instanceof Object[])) {
+        value = RestObjectMapperFactory.getRestObjectMapper()
+            .convertValue(value, Object[].class);
+      }
       encode(builder, name, Arrays.asList((Object[]) value));
       return;
     }
diff --git 
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDataTypesAnnotationsSchema.java
 
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDataTypesAnnotationsSchema.java
new file mode 100644
index 000000000..6234b0a99
--- /dev/null
+++ 
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDataTypesAnnotationsSchema.java
@@ -0,0 +1,54 @@
+/*
+ * 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.demo.springmvc.client;
+
+import org.apache.servicecomb.demo.CategorizedTestCase;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.provider.pojo.RpcReference;
+import org.springframework.stereotype.Component;
+
+@Component
+public class TestDataTypesAnnotationsSchema implements CategorizedTestCase {
+  public interface DataTypesAnnotationsItf {
+    int[] testIntArrayQuery(int[] param);
+
+    Integer[] testIntegerArrayQuery(Integer[] param);
+  }
+
+  @RpcReference(schemaId = "DataTypesAnnotationsSchema", microserviceName = 
"springmvc")
+  private DataTypesAnnotationsItf client;
+
+  @Override
+  public void testAllTransport() throws Exception {
+    testIntArrayQuery();
+    testIntegerArrayQuery();
+  }
+
+  private void testIntArrayQuery() {
+    int[] request = new int[] {5, 11, 4};
+    int[] result = client.testIntArrayQuery(request);
+    TestMgr.check(request.length, result.length);
+    TestMgr.check(request[1], result[1]);
+  }
+
+  private void testIntegerArrayQuery() {
+    Integer[] request = new Integer[] {5, 11, 4};
+    Integer[] result = client.testIntegerArrayQuery(request);
+    TestMgr.check(request.length, result.length);
+    TestMgr.check(request[1], result[1]);
+  }
+}
diff --git 
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/DataTypesAnnotationsSchema.java
 
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/DataTypesAnnotationsSchema.java
new file mode 100644
index 000000000..21077009c
--- /dev/null
+++ 
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/DataTypesAnnotationsSchema.java
@@ -0,0 +1,36 @@
+/*
+ * 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.demo.springmvc.server;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@RestSchema(schemaId = "DataTypesAnnotationsSchema")
+@RequestMapping(path = "/dataTypes")
+public class DataTypesAnnotationsSchema {
+  @GetMapping(path = "/testIntArrayQuery")
+  public int[] testIntArrayQuery(@RequestParam("param") int[] param) {
+    return param;
+  }
+
+  @GetMapping(path = "/testIntegerArrayQuery")
+  public Integer[] testIntegerArrayQuery(@RequestParam("param") Integer[] 
param) {
+    return param;
+  }
+}
diff --git 
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
 
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
index b90f6762d..172817164 100644
--- 
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
+++ 
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java
@@ -91,9 +91,9 @@ public class ProducerTestsAfterBootup implements BootListener 
{
 
   public void testRegisteredBasePath() {
     if 
(DynamicPropertyFactory.getInstance().getBooleanProperty("servicecomb.test.vert.transport",
 true).get()) {
-      TestMgr.check(22, 
RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
+      TestMgr.check(23, 
RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
     } else {
-      TestMgr.check(24, 
RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
+      TestMgr.check(25, 
RegistrationManager.INSTANCE.getMicroservice().getPaths().size());
     }
   }
 

Reply via email to