Skip to content

Commit

Permalink
Fix ResourceRegion HttpMessageConverter write checks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bclozel committed Jun 11, 2018
1 parent ef41dcf commit 05ff8b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
Expand Down Expand Up @@ -119,7 +119,7 @@ public boolean canWrite(@Nullable Type type, @Nullable Class<?> clazz, @Nullable
}

Class<?> typeArgumentClass = (Class<?>) typeArgument;
return typeArgumentClass.isAssignableFrom(ResourceRegion.class);
return ResourceRegion.class.isAssignableFrom(typeArgumentClass);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
Expand Down Expand Up @@ -64,6 +64,7 @@ public void canReadResource() {
public void canWriteResource() {
assertTrue(converter.canWrite(ResourceRegion.class, null, MediaType.APPLICATION_OCTET_STREAM));
assertTrue(converter.canWrite(ResourceRegion.class, null, MediaType.ALL));
assertFalse(converter.canWrite(Object.class, null, MediaType.ALL));
}

@Test
Expand All @@ -74,6 +75,8 @@ public void canWriteResourceCollection() {

assertFalse(converter.canWrite(List.class, MediaType.APPLICATION_OCTET_STREAM));
assertFalse(converter.canWrite(List.class, MediaType.ALL));
Type resourceObjectList = new ParameterizedTypeReference<List<Object>>() {}.getType();
assertFalse(converter.canWrite(resourceObjectList, null, MediaType.ALL));
}

@Test
Expand Down

0 comments on commit 05ff8b7

Please sign in to comment.