Properly handle Flux<?> and Flux<Object> in WebFlux

Issue: SPR-15464
This commit is contained in:
Rossen Stoyanchev
2017-04-20 08:40:15 -04:00
parent a93698487e
commit cc102c2fcd
22 changed files with 72 additions and 37 deletions

View File

@@ -86,7 +86,7 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter<Objec
@Override
public boolean canWrite(ResolvableType elementType, MediaType mediaType) {
return mediaType == null || MediaType.TEXT_EVENT_STREAM.includes(mediaType) ||
ServerSentEvent.class.isAssignableFrom(elementType.getRawClass());
ServerSentEvent.class.isAssignableFrom(elementType.resolve(Object.class));
}
@Override

View File

@@ -104,10 +104,10 @@ public class Jackson2JsonEncoder extends Jackson2CodecSupport implements HttpMes
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
Class<?> clazz = elementType.getRawClass();
// Skip String: StringDecoder + "*/*" comes after
return (!String.class.isAssignableFrom(elementType.resolve(Object.class)) &&
this.objectMapper.canSerialize(clazz) && supportsMimeType(mimeType));
Class<?> clazz = elementType.resolve(Object.class);
return Object.class.equals(clazz) ||
!String.class.isAssignableFrom(elementType.resolve(clazz)) &&
this.objectMapper.canSerialize(clazz) && supportsMimeType(mimeType);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -55,7 +55,7 @@ public class Jaxb2XmlEncoder extends AbstractSingleValueEncoder<Object> {
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType) {
if (super.canEncode(elementType, mimeType)) {
Class<?> outputClass = elementType.getRawClass();
Class<?> outputClass = elementType.resolve(Object.class);
return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
outputClass.isAnnotationPresent(XmlType.class));
}