Skip to content
Advertisement

Getting a list of JSON Users objs. in a POST request and return a response also as JSON

This is my first time using spring-webflux with SpringBoot. My goal is to create an API that accepts a list of Users in JSON format in the body of a POST and return a response with that list also in JSON format ordered by a date field. The ordering is not a problem but I do not know very well how to make this architecture. So far I have:

  • UserWebfluxApplication (with the @SpringBootApplication)

  • model/User.java (id, name, surname, creationDate)

  • service/UserService.java (Interface)

  • service/UserServiceImpl.java implementing the Interface with the WebClient and with the following method:

    JavaScript
  • controller/UserController.java (Here I don’t know how can I construct this class for reach my achievement testing the request for example with curl, Postman, or whatever). So far I’ve this in the UserController:

    JavaScript

The json request will be like:

JavaScript

Thank you in advance.

Advertisement

Answer

Finally I’ve solved it by the following:

Controller:

JavaScript

Service:

JavaScript

The main problem I was facing is that I was trying to manage the list with Mono rather than Flux.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement