Browse Source

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
pull/1856/head
Brian Clozel 7 years ago
parent
commit
05ff8b722d
  1. 4
      spring-web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java
  2. 5
      spring-web/src/test/java/org/springframework/http/converter/ResourceRegionHttpMessageConverterTests.java

4
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; Class<?> typeArgumentClass = (Class<?>) typeArgument;
return typeArgumentClass.isAssignableFrom(ResourceRegion.class); return ResourceRegion.class.isAssignableFrom(typeArgumentClass);
} }
@Override @Override

5
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -64,6 +64,7 @@ public class ResourceRegionHttpMessageConverterTests {
public void canWriteResource() { public void canWriteResource() {
assertTrue(converter.canWrite(ResourceRegion.class, null, MediaType.APPLICATION_OCTET_STREAM)); assertTrue(converter.canWrite(ResourceRegion.class, null, MediaType.APPLICATION_OCTET_STREAM));
assertTrue(converter.canWrite(ResourceRegion.class, null, MediaType.ALL)); assertTrue(converter.canWrite(ResourceRegion.class, null, MediaType.ALL));
assertFalse(converter.canWrite(Object.class, null, MediaType.ALL));
} }
@Test @Test
@ -74,6 +75,8 @@ public class ResourceRegionHttpMessageConverterTests {
assertFalse(converter.canWrite(List.class, MediaType.APPLICATION_OCTET_STREAM)); assertFalse(converter.canWrite(List.class, MediaType.APPLICATION_OCTET_STREAM));
assertFalse(converter.canWrite(List.class, MediaType.ALL)); assertFalse(converter.canWrite(List.class, MediaType.ALL));
Type resourceObjectList = new ParameterizedTypeReference<List<Object>>() {}.getType();
assertFalse(converter.canWrite(resourceObjectList, null, MediaType.ALL));
} }
@Test @Test

Loading…
Cancel
Save