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

albumenj pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.3 by this push:
     new 044a775373 fix(rest): Fix rest convert error (#13783)
044a775373 is described below

commit 044a775373f91b7a24dc8f62d9d5fea825ce0fab
Author: Sean Yang <[email protected]>
AuthorDate: Mon Feb 26 10:05:51 2024 +0800

    fix(rest): Fix rest convert error (#13783)
---
 .../tri/rest/support/jaxrs/JaxrsRestToolKit.java   | 14 ++++++++++
 .../jaxrs/MultivaluedMapCreationConverter.java     | 31 ----------------------
 .../org.apache.dubbo.common.convert.Converter      |  1 -
 .../tri/rest/argument/GeneralTypeConverter.java    | 14 +++-------
 4 files changed, 17 insertions(+), 43 deletions(-)

diff --git 
a/dubbo-plugin/dubbo-rest-jaxrs/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/jaxrs/JaxrsRestToolKit.java
 
b/dubbo-plugin/dubbo-rest-jaxrs/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/jaxrs/JaxrsRestToolKit.java
index 85e66b21e4..95ef839b87 100644
--- 
a/dubbo-plugin/dubbo-rest-jaxrs/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/jaxrs/JaxrsRestToolKit.java
+++ 
b/dubbo-plugin/dubbo-rest-jaxrs/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/jaxrs/JaxrsRestToolKit.java
@@ -23,6 +23,9 @@ import org.apache.dubbo.rpc.protocol.tri.rest.RestConstants;
 import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.ParameterMeta;
 import org.apache.dubbo.rpc.protocol.tri.rest.util.DefaultRestToolKit;
 
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+
 final class JaxrsRestToolKit extends DefaultRestToolKit {
 
     private final BeanArgumentBinder binder;
@@ -32,6 +35,17 @@ final class JaxrsRestToolKit extends DefaultRestToolKit {
         binder = new BeanArgumentBinder(frameworkModel);
     }
 
+    @Override
+    public Object convert(Object value, ParameterMeta parameter) {
+        if (MultivaluedMap.class.isAssignableFrom(parameter.getType())) {
+            if (value instanceof MultivaluedMap) {
+                return value;
+            }
+            return typeConverter.convert(value, MultivaluedHashMap.class);
+        }
+        return super.convert(value, parameter);
+    }
+
     @Override
     public int getDialect() {
         return RestConstants.DIALECT_JAXRS;
diff --git 
a/dubbo-plugin/dubbo-rest-jaxrs/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/jaxrs/MultivaluedMapCreationConverter.java
 
b/dubbo-plugin/dubbo-rest-jaxrs/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/jaxrs/MultivaluedMapCreationConverter.java
deleted file mode 100644
index eb9e9df3c8..0000000000
--- 
a/dubbo-plugin/dubbo-rest-jaxrs/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/support/jaxrs/MultivaluedMapCreationConverter.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.dubbo.rpc.protocol.tri.rest.support.jaxrs;
-
-import org.apache.dubbo.common.convert.Converter;
-
-import javax.ws.rs.core.MultivaluedHashMap;
-import javax.ws.rs.core.MultivaluedMap;
-
-@SuppressWarnings("rawtypes")
-public class MultivaluedMapCreationConverter implements Converter<Integer, 
MultivaluedMap> {
-
-    @Override
-    public MultivaluedMap<?, ?> convert(Integer source) {
-        return new MultivaluedHashMap<>(source);
-    }
-}
diff --git 
a/dubbo-plugin/dubbo-rest-jaxrs/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.convert.Converter
 
b/dubbo-plugin/dubbo-rest-jaxrs/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.convert.Converter
deleted file mode 100644
index 1af72a984d..0000000000
--- 
a/dubbo-plugin/dubbo-rest-jaxrs/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.convert.Converter
+++ /dev/null
@@ -1 +0,0 @@
-integer-to-multi-valued-map=org.apache.dubbo.rpc.protocol.tri.rest.support.jaxrs.MultivaluedMapCreationConverter
diff --git 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/argument/GeneralTypeConverter.java
 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/argument/GeneralTypeConverter.java
index 995334da7f..ee9fb15221 100644
--- 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/argument/GeneralTypeConverter.java
+++ 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/argument/GeneralTypeConverter.java
@@ -730,11 +730,11 @@ public class GeneralTypeConverter implements 
TypeConverter {
     }
 
     protected Collection customCreateCollection(Class targetClass, int size) {
-        return null;
+        return converterUtil == null ? null : (Collection) 
converterUtil.convertIfPossible(size, targetClass);
     }
 
-    private Map customCreateMap(Class targetClass, int size) {
-        return null;
+    protected Map customCreateMap(Class targetClass, int size) {
+        return converterUtil == null ? null : (Map) 
converterUtil.convertIfPossible(size, targetClass);
     }
 
     private Collection createCollection(Class targetClass, int size) {
@@ -792,10 +792,6 @@ public class GeneralTypeConverter implements TypeConverter 
{
         if (collection != null) {
             return collection;
         }
-        collection = (Collection) converterUtil.convertIfPossible(size, 
targetClass);
-        if (collection != null) {
-            return collection;
-        }
         if (targetClass.isAssignableFrom(ArrayList.class)) {
             return new ArrayList<>(size);
         }
@@ -934,10 +930,6 @@ public class GeneralTypeConverter implements TypeConverter 
{
         if (map != null) {
             return map;
         }
-        map = (Map) converterUtil.convertIfPossible(size, targetClass);
-        if (map != null) {
-            return map;
-        }
         if (targetClass.isAssignableFrom(LinkedHashMap.class)) {
             return CollectionUtils.newLinkedHashMap(size);
         }

Reply via email to