EncoderHttpMessageWriter tries to send wildcard type in response header

This commit is contained in:
soldierkam
2016-09-28 22:27:55 +02:00
committed by Rossen Stoyanchev
parent ced6559941
commit e5158d47e0
5 changed files with 80 additions and 40 deletions

View File

@@ -110,13 +110,15 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> {
* Used when {@link #write} is called without a concrete content type.
*
* <p>By default returns the first of {@link Encoder#getEncodableMimeTypes()
* encodableMimeTypes}, if any.
* encodableMimeTypes} that is concrete({@link MediaType#isConcrete()}), if any.
*
* @param elementType the type of element for encoding
* @return the content type, or {@code null}
*/
protected MediaType getDefaultContentType(ResolvableType elementType) {
return (!this.writableMediaTypes.isEmpty() ? this.writableMediaTypes.get(0) : null);
return writableMediaTypes.stream()
.filter(MediaType::isConcrete)
.findFirst().orElse(null);
}
}