Home > Enterprise >  What are the drawbacks of @RequestBody in Spring MVC?
What are the drawbacks of @RequestBody in Spring MVC?

Time:03-24

That's a silly question but I had this question during the interview of a some company. I had a stateless backend using Java Spring and expected the full DTO from the request as a @RequestBody but they asked me what are the drawbacks of expecting a full DTO as @RequestBody and I couldn't answer it.

If my application is stateless, how should I expect the model from the controller? Or is stateless backend not a good idea if you expect the whole model to use it in the service-side?

CodePudding user response:

  1. With DTO you usually send more data that is actually needed by remote server (although one of the main point of DTO is to reduce the number of remote calls by sending more data)
  2. It maybe not straightforward to transfer DTOs to domain objects, if DTOs were complex
  3. Serialization/de-serialization also could be a burden[for example binary or text]. but if you control both client and server it is not a big deal.
  4. With big DTOs it become harder to keep clients and servers synchronized of changes
  • Related