From 7cbd9e1d93b712f5ac098f06b7407dfc90e0d1d8 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 12 Jan 2010 15:31:30 +0000 Subject: [PATCH] fixed type assignability check for wildcarded Map (SPR-6676) --- .../core/convert/TypeDescriptor.java | 4 ++-- .../GenericConversionServiceTests.java | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index eb01543c825..25e6daeece7 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -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))); } diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java index c9e72667b52..18c27c33550 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java @@ -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 raw = new HashMap(); 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 input = new LinkedHashMap(); + 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 { + private static class MyBaseInterfaceConverter implements Converter { public String convert(MyBaseInterface source) { return "RESULT"; @@ -205,4 +216,6 @@ public class GenericConversionServiceTests { } + public static Map wildcardMap; + }