Skip to content

Return value doesn't serialize to JSON when return type is Mono of Interface in WebFlux #22803

Closed
@freddieyyh

Description

@freddieyyh

In WebMVC type application, Spring's message converter can convert the return value to a proper message(like a JSON) when controller return type declared by interface.

But, Webflux's behavior is different.

For example, we have Car class that implements Vehicle interface.

public interface Vehicle {
}

public class Car implements Vehicle {
    private String gearType;
}

And then there is a controller method like that.

@GetMapping("vehicle")
public Vehicle getVehicle() {
    return new Car();
}

I can get a json response of Car class with content-type: application/json header.

But, webflux's result is defferent.

@GetMapping("vehicle")
public Mono<Vehicle> getVehicle() {
    return Mono.just(new Car());
}

It only supports a 'content-type: text/event-stream' when return type is a mono of interface.
Is it a bug?

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