@@ -124,6 +124,7 @@ protected Mono<Void> writeBody(@Nullable Object body, MethodParameter bodyParame
124
124
125
125
Publisher <?> publisher ;
126
126
ResolvableType elementType ;
127
+ ResolvableType actualElementType ;
127
128
if (adapter != null ) {
128
129
publisher = adapter .toPublisher (body );
129
130
boolean isUnwrapped = KotlinDetector .isKotlinReflectPresent () &&
@@ -132,11 +133,12 @@ protected Mono<Void> writeBody(@Nullable Object body, MethodParameter bodyParame
132
133
!COROUTINES_FLOW_CLASS_NAME .equals (bodyType .toClass ().getName ());
133
134
ResolvableType genericType = isUnwrapped ? bodyType : bodyType .getGeneric ();
134
135
elementType = getElementType (adapter , genericType );
136
+ actualElementType = elementType ;
135
137
}
136
138
else {
137
139
publisher = Mono .justOrEmpty (body );
138
- elementType = ( bodyType . toClass () == Object . class && body != null ?
139
- ResolvableType . forInstance ( body ) : bodyType );
140
+ actualElementType = body != null ? ResolvableType . forInstance ( body ) : bodyType ;
141
+ elementType = ( bodyType . toClass () == Object . class && body != null ? actualElementType : bodyType );
140
142
}
141
143
142
144
if (elementType .resolve () == void .class || elementType .resolve () == Void .class ) {
@@ -151,7 +153,7 @@ protected Mono<Void> writeBody(@Nullable Object body, MethodParameter bodyParame
151
153
(publisher instanceof Mono ? "0..1" : "0..N" ) + " [" + elementType + "]" );
152
154
}
153
155
for (HttpMessageWriter <?> writer : getMessageWriters ()) {
154
- if (writer .canWrite (elementType , bestMediaType )) {
156
+ if (writer .canWrite (actualElementType , bestMediaType )) {
155
157
return writer .write ((Publisher ) publisher , actualType , elementType ,
156
158
bestMediaType , exchange .getRequest (), exchange .getResponse (),
157
159
Hints .from (Hints .LOG_PREFIX_HINT , logPrefix ));
0 commit comments