I'm trying to adapt an application that works well with Spring MVC but that has a different behavior with Spring WebFlux
Here's my code with Spring Boot 5 - Spring MVC :
The controller :
@RestController
public class MyRestController {
@GetMapping("/test/{id}/{label}")
public ResponseEntity<Payload> test(@ModelAttribute Payload payload) {
return new ResponseEntity<>(payload,HttpStatus.OK);
}
}
The Payload object :
public class Payload {
@NotNull
private int id;
private String label;
public Payload() {}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
My pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
I don't have written any custom converter, Spring populate my payload object automatically, everything is fine.
When I call :
http://localhost:8080/test/25/helloWorld
Response is
{"id":25,"label":"helloWorld"}
Then, I only change my pom.xml, switching from web to webflux :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
</dependencies>
And my Payload Object isn't populated anymore.
When I call :
http://localhost:8080/test/25/helloWorld
Response is
{"id":0,"label":null}
I know I could write a converter and register it with @ControllerAdvice, but I can't imagine that there isn't an automated solution to make it works again as it has always worked with Spring Web.
Does anyone already encountered the same problem as me ?
Thanks,
Julien