Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
9b2da37f
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9b2da37f
编写于
9月 12, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
GenericConversionService detects enum subclasses as well
Issue: SPR-12181
上级
553930a9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
6 deletion
+33
-6
spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
...mework/core/convert/support/GenericConversionService.java
+2
-2
spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java
...k/core/convert/support/GenericConversionServiceTests.java
+31
-4
未找到文件。
spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
浏览文件 @
9b2da37f
...
@@ -568,14 +568,14 @@ public class GenericConversionService implements ConfigurableConversionService {
...
@@ -568,14 +568,14 @@ public class GenericConversionService implements ConfigurableConversionService {
Class
<?>
candidate
=
hierarchy
.
get
(
i
);
Class
<?>
candidate
=
hierarchy
.
get
(
i
);
candidate
=
(
array
?
candidate
.
getComponentType
()
:
ClassUtils
.
resolvePrimitiveIfNecessary
(
candidate
));
candidate
=
(
array
?
candidate
.
getComponentType
()
:
ClassUtils
.
resolvePrimitiveIfNecessary
(
candidate
));
Class
<?>
superclass
=
candidate
.
getSuperclass
();
Class
<?>
superclass
=
candidate
.
getSuperclass
();
if
(
candidate
.
getSuperclass
()
!=
null
&&
superclass
!=
Object
.
class
&&
superclass
!=
Enum
.
class
)
{
if
(
superclass
!=
null
&&
superclass
!=
Object
.
class
&&
superclass
!=
Enum
.
class
)
{
addToClassHierarchy
(
i
+
1
,
candidate
.
getSuperclass
(),
array
,
hierarchy
,
visited
);
addToClassHierarchy
(
i
+
1
,
candidate
.
getSuperclass
(),
array
,
hierarchy
,
visited
);
}
}
addInterfacesToClassHierarchy
(
candidate
,
array
,
hierarchy
,
visited
);
addInterfacesToClassHierarchy
(
candidate
,
array
,
hierarchy
,
visited
);
i
++;
i
++;
}
}
if
(
type
.
isEnum
(
))
{
if
(
Enum
.
class
.
isAssignableFrom
(
type
))
{
addToClassHierarchy
(
hierarchy
.
size
(),
Enum
.
class
,
array
,
hierarchy
,
visited
);
addToClassHierarchy
(
hierarchy
.
size
(),
Enum
.
class
,
array
,
hierarchy
,
visited
);
addToClassHierarchy
(
hierarchy
.
size
(),
Enum
.
class
,
false
,
hierarchy
,
visited
);
addToClassHierarchy
(
hierarchy
.
size
(),
Enum
.
class
,
false
,
hierarchy
,
visited
);
addInterfacesToClassHierarchy
(
Enum
.
class
,
array
,
hierarchy
,
visited
);
addInterfacesToClassHierarchy
(
Enum
.
class
,
array
,
hierarchy
,
visited
);
...
...
spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java
浏览文件 @
9b2da37f
...
@@ -63,6 +63,7 @@ public class GenericConversionServiceTests {
...
@@ -63,6 +63,7 @@ public class GenericConversionServiceTests {
private
GenericConversionService
conversionService
=
new
GenericConversionService
();
private
GenericConversionService
conversionService
=
new
GenericConversionService
();
@Test
@Test
public
void
canConvert
()
{
public
void
canConvert
()
{
assertFalse
(
conversionService
.
canConvert
(
String
.
class
,
Integer
.
class
));
assertFalse
(
conversionService
.
canConvert
(
String
.
class
,
Integer
.
class
));
...
@@ -750,6 +751,13 @@ public class GenericConversionServiceTests {
...
@@ -750,6 +751,13 @@ public class GenericConversionServiceTests {
assertEquals
(
"A"
,
result
);
assertEquals
(
"A"
,
result
);
}
}
@Test
public
void
testSubclassOfEnumToString
()
throws
Exception
{
conversionService
.
addConverter
(
new
EnumToStringConverter
(
conversionService
));
String
result
=
conversionService
.
convert
(
EnumWithSubclass
.
FIRST
,
String
.
class
);
assertEquals
(
"FIRST"
,
result
);
}
@Test
@Test
public
void
testEnumWithInterfaceToStringConversion
()
{
public
void
testEnumWithInterfaceToStringConversion
()
{
// SPR-9692
// SPR-9692
...
@@ -865,6 +873,7 @@ public class GenericConversionServiceTests {
...
@@ -865,6 +873,7 @@ public class GenericConversionServiceTests {
@ExampleAnnotation
@ExampleAnnotation
public
String
annotatedString
;
public
String
annotatedString
;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
static
@interface
ExampleAnnotation
{
public
static
@interface
ExampleAnnotation
{
}
}
...
@@ -907,8 +916,7 @@ public class GenericConversionServiceTests {
...
@@ -907,8 +916,7 @@ public class GenericConversionServiceTests {
}
}
@Override
@Override
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
public
Object
convert
(
Object
source
,
TypeDescriptor
sourceType
,
TypeDescriptor
targetType
)
{
TypeDescriptor
targetType
)
{
return
null
;
return
null
;
}
}
...
@@ -945,14 +953,19 @@ public class GenericConversionServiceTests {
...
@@ -945,14 +953,19 @@ public class GenericConversionServiceTests {
}
}
}
}
interface
MyEnumBaseInterface
{
interface
MyEnumBaseInterface
{
String
getBaseCode
();
String
getBaseCode
();
}
}
interface
MyEnumInterface
extends
MyEnumBaseInterface
{
interface
MyEnumInterface
extends
MyEnumBaseInterface
{
String
getCode
();
String
getCode
();
}
}
public
static
enum
MyEnum
implements
MyEnumInterface
{
public
static
enum
MyEnum
implements
MyEnumInterface
{
A
(
"1"
),
A
(
"1"
),
...
@@ -977,6 +990,17 @@ public class GenericConversionServiceTests {
...
@@ -977,6 +990,17 @@ public class GenericConversionServiceTests {
}
}
public
enum
EnumWithSubclass
{
FIRST
{
@Override
public
String
toString
()
{
return
"1st"
;
}
}
}
public
static
class
MyStringToRawCollectionConverter
implements
Converter
<
String
,
Collection
>
{
public
static
class
MyStringToRawCollectionConverter
implements
Converter
<
String
,
Collection
>
{
@Override
@Override
...
@@ -985,6 +1009,7 @@ public class GenericConversionServiceTests {
...
@@ -985,6 +1009,7 @@ public class GenericConversionServiceTests {
}
}
}
}
public
static
class
MyStringToGenericCollectionConverter
implements
Converter
<
String
,
Collection
<?>>
{
public
static
class
MyStringToGenericCollectionConverter
implements
Converter
<
String
,
Collection
<?>>
{
@Override
@Override
...
@@ -993,6 +1018,7 @@ public class GenericConversionServiceTests {
...
@@ -993,6 +1018,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
MyEnumInterfaceToStringConverter
<
T
extends
MyEnumInterface
>
implements
Converter
<
T
,
String
>
{
private
static
class
MyEnumInterfaceToStringConverter
<
T
extends
MyEnumInterface
>
implements
Converter
<
T
,
String
>
{
@Override
@Override
...
@@ -1001,6 +1027,7 @@ public class GenericConversionServiceTests {
...
@@ -1001,6 +1027,7 @@ public class GenericConversionServiceTests {
}
}
}
}
private
static
class
StringToMyEnumInterfaceConverterFactory
implements
ConverterFactory
<
String
,
MyEnumInterface
>
{
private
static
class
StringToMyEnumInterfaceConverterFactory
implements
ConverterFactory
<
String
,
MyEnumInterface
>
{
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
...
@@ -1024,9 +1051,9 @@ public class GenericConversionServiceTests {
...
@@ -1024,9 +1051,9 @@ public class GenericConversionServiceTests {
return
null
;
return
null
;
}
}
}
}
}
}
private
static
class
StringToMyEnumBaseInterfaceConverterFactory
implements
ConverterFactory
<
String
,
MyEnumBaseInterface
>
{
private
static
class
StringToMyEnumBaseInterfaceConverterFactory
implements
ConverterFactory
<
String
,
MyEnumBaseInterface
>
{
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
...
@@ -1050,7 +1077,6 @@ public class GenericConversionServiceTests {
...
@@ -1050,7 +1077,6 @@ public class GenericConversionServiceTests {
return
null
;
return
null
;
}
}
}
}
}
}
...
@@ -1062,6 +1088,7 @@ public class GenericConversionServiceTests {
...
@@ -1062,6 +1088,7 @@ public class GenericConversionServiceTests {
}
}
}
}
public
static
class
MyStringToIntegerCollectionConverter
implements
Converter
<
String
,
Collection
<
Integer
>>
{
public
static
class
MyStringToIntegerCollectionConverter
implements
Converter
<
String
,
Collection
<
Integer
>>
{
@Override
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录