- I have searched the issues of this repository and believe that this is not a duplicate.
- I have checked the FAQ of this repository and believe that this is not a duplicate.
Environment
- Dubbo version: 2.7.3
- Operating System version: linux
- Java version: 1.8
Steps to reproduce this issue
- MapTypeBuilder 中写死map泛型参数数目必须为2,导致在使用外部开源的原生类型的map判断报错。
@Override
public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, TypeDefinition> typeCache) {
if (!(type instanceof ParameterizedType)) {
return new TypeDefinition(clazz.getName());
}
ParameterizedType parameterizedType = (ParameterizedType) type;
Type[] actualTypeArgs = parameterizedType.getActualTypeArguments();
if (actualTypeArgs == null || actualTypeArgs.length != 2) {
throw new IllegalArgumentException(MessageFormat.format(
"[ServiceDefinitionBuilder] Map type [{0}] with unexpected amount of arguments [{1}]." + actualTypeArgs,
new Object[] {type, actualTypeArgs}));
}
for (Type actualType : actualTypeArgs) {
if (actualType instanceof ParameterizedType) {
// Nested collection or map.
Class<?> rawType = (Class<?>) ((ParameterizedType) actualType).getRawType();
TypeDefinitionBuilder.build(actualType, rawType, typeCache);
} else if (actualType instanceof Class<?>) {
Class<?> actualClass = (Class<?>) actualType;
if (actualClass.isArray() || actualClass.isEnum()) {
TypeDefinitionBuilder.build(null, actualClass, typeCache);
} else {
DefaultTypeBuilder.build(actualClass, typeCache);
}
}
}
如下所示,参数长度为1。
package it.unimi.dsi.fastutil.ints;
public interface Int2ObjectMap<V> extends Int2ObjectFunction<V>, Map<Integer, V> {}
该类来自于
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
</dependency>
Expected Result
是否可以判断他的上层实现来进行判断
能否定义一个order接口,然后sort一下,这样外部拓展的时候可以手动调准新增的builder的顺序
2条答案
按热度按时间kkbh8khc1#
遇到同样的问题
public class WebResult extends HashMap<String, Object> implements Serializable {
.........
}
daupos2t2#
1.创建自定义TypeBuilder
META-INF
下创建dubbo/internal/org.apache.dubbo.metadata.definition.builder.TypeBuilder
文件#6306