Skip to content

Improve ResourceHttpMessageConverter target type support #36368

@sparecycles

Description

@sparecycles

Not an issue. Just noticed while digging through the implementation: Looks like the ResourceHttpMessageConverter can construct a value that doesn't implement the requested type if that type extends the non-final ByteArrayResource type.

else if (Resource.class == clazz || ByteArrayResource.class.isAssignableFrom(clazz)) {
byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody());
return new ByteArrayResource(body) {
@Override
public @Nullable String getFilename() {
return inputMessage.getHeaders().getContentDisposition().getFilename();
}
};
}

the condition should probably be

 else if (Resource.class == clazz || clazz.isAssignableFrom(ByteArrayResource.class)) { 

which I guess could then be simplified to

 else if (clazz.isAssignableFrom(ByteArrayResource.class)) { 

(but maybe this simplification would be a de-optimization if clazz == Resource.class is a common case).

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions