Skip to content

Commit 96eba8b

Browse files
committed
Fix ResourceRegion HttpMessageConverter write checks
This commit fixes the write checks for `ResourceRegionHttpMessageConverter`, which was previously not checking properly the parameterized type (e.g. in case of a `List<Something>`). Issue: SPR-16932 (Cherry-picked from 05ff8b7)
1 parent be52299 commit 96eba8b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

spring-web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -119,7 +119,7 @@ public boolean canWrite(@Nullable Type type, @Nullable Class<?> clazz, @Nullable
119119
}
120120

121121
Class<?> typeArgumentClass = (Class<?>) typeArgument;
122-
return typeArgumentClass.isAssignableFrom(ResourceRegion.class);
122+
return ResourceRegion.class.isAssignableFrom(typeArgumentClass);
123123
}
124124

125125
@Override

spring-web/src/test/java/org/springframework/http/converter/ResourceRegionHttpMessageConverterTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,6 +64,7 @@ public void canReadResource() {
6464
public void canWriteResource() {
6565
assertTrue(converter.canWrite(ResourceRegion.class, null, MediaType.APPLICATION_OCTET_STREAM));
6666
assertTrue(converter.canWrite(ResourceRegion.class, null, MediaType.ALL));
67+
assertFalse(converter.canWrite(Object.class, null, MediaType.ALL));
6768
}
6869

6970
@Test
@@ -74,6 +75,8 @@ public void canWriteResourceCollection() {
7475

7576
assertFalse(converter.canWrite(List.class, MediaType.APPLICATION_OCTET_STREAM));
7677
assertFalse(converter.canWrite(List.class, MediaType.ALL));
78+
Type resourceObjectList = new ParameterizedTypeReference<List<Object>>() {}.getType();
79+
assertFalse(converter.canWrite(resourceObjectList, null, MediaType.ALL));
7780
}
7881

7982
@Test

0 commit comments

Comments
 (0)