fixed type assignability check for wildcarded Map (SPR-6676)
This commit is contained in:
parent
1ff99f2569
commit
7cbd9e1d93
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -456,7 +456,7 @@ public class TypeDescriptor {
|
|||
|
||||
private boolean isTypeAssignableTo(Class<?> clazz) {
|
||||
Class<?> type = getType();
|
||||
return (type != null && ClassUtils.isAssignable(clazz, type));
|
||||
return (type != null && (clazz == null || ClassUtils.isAssignable(clazz, type)));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -18,6 +18,7 @@ package org.springframework.core.convert.support;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -164,7 +165,7 @@ public class GenericConversionServiceTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMapToObjectConversionBug() {
|
||||
public void testMapToObjectConversion() {
|
||||
GenericConversionService conversionService = new GenericConversionService();
|
||||
Map<Object, Object> raw = new HashMap<Object, Object>();
|
||||
raw.put("key", "value");
|
||||
|
|
@ -181,6 +182,16 @@ public class GenericConversionServiceTests {
|
|||
assertEquals("RESULT", converted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWildcardMap() throws Exception {
|
||||
GenericConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
|
||||
Map<String, String> input = new LinkedHashMap<String, String>();
|
||||
input.put("key", "value");
|
||||
Object converted = conversionService.convert(input, TypeDescriptor.forObject(input),
|
||||
new TypeDescriptor(getClass().getField("wildcardMap")));
|
||||
assertSame(input, converted);
|
||||
}
|
||||
|
||||
|
||||
private interface MyBaseInterface {
|
||||
|
||||
|
|
@ -197,7 +208,7 @@ public class GenericConversionServiceTests {
|
|||
}
|
||||
|
||||
|
||||
private class MyBaseInterfaceConverter implements Converter<MyBaseInterface, String> {
|
||||
private static class MyBaseInterfaceConverter implements Converter<MyBaseInterface, String> {
|
||||
|
||||
public String convert(MyBaseInterface source) {
|
||||
return "RESULT";
|
||||
|
|
@ -205,4 +216,6 @@ public class GenericConversionServiceTests {
|
|||
}
|
||||
|
||||
|
||||
public static Map<String, ?> wildcardMap;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue