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/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new c31ad5d3e [SCB-2854]query parameter support primitive array (#4203)
c31ad5d3e is described below
commit c31ad5d3e364fc42bc6078ce993fc8ca039e52f7
Author: liubao68 <[email protected]>
AuthorDate: Fri Jan 26 14:15:46 2024 +0800
[SCB-2854]query parameter support primitive array (#4203)
---
.../rest/codec/query/AbstractQueryCodec.java | 5 ++
.../client/TestDataTypesAnnotationsSchema.java | 54 ++++++++++++++++++++++
.../server/DataTypesAnnotationsSchema.java | 36 +++++++++++++++
3 files changed, 95 insertions(+)
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 5e0d19630..0ba395bb4 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
@@ -20,6 +20,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
import
org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
public abstract class AbstractQueryCodec implements QueryCodec {
@@ -43,6 +44,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;
+ }
+}