From 05ff8b722d13d8a59adf8890ccd751ea90fc7acb Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Mon, 11 Jun 2018 22:43:59 +0200 Subject: [PATCH] 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`). Issue: SPR-16932 --- .../http/converter/ResourceRegionHttpMessageConverter.java | 4 ++-- .../converter/ResourceRegionHttpMessageConverterTests.java | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java index 6d2d3c8808..6442759085 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java @@ -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. @@ -119,7 +119,7 @@ public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessa } Class typeArgumentClass = (Class) typeArgument; - return typeArgumentClass.isAssignableFrom(ResourceRegion.class); + return ResourceRegion.class.isAssignableFrom(typeArgumentClass); } @Override diff --git a/spring-web/src/test/java/org/springframework/http/converter/ResourceRegionHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/ResourceRegionHttpMessageConverterTests.java index e05595569b..274d3ba5ef 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/ResourceRegionHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/ResourceRegionHttpMessageConverterTests.java @@ -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. @@ -64,6 +64,7 @@ public class ResourceRegionHttpMessageConverterTests { 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 @@ -74,6 +75,8 @@ public class ResourceRegionHttpMessageConverterTests { assertFalse(converter.canWrite(List.class, MediaType.APPLICATION_OCTET_STREAM)); assertFalse(converter.canWrite(List.class, MediaType.ALL)); + Type resourceObjectList = new ParameterizedTypeReference>() {}.getType(); + assertFalse(converter.canWrite(resourceObjectList, null, MediaType.ALL)); } @Test