DEV Community

Discussion on: SpringBoot - Contextualizing serialization

Collapse
 
martinhaeusler profile image
Martin Häusler

I know that it's very tempting to use JSON views on top of entities, but please don't. Every time I did that I lived to regret it. The problem is that your database schema will evolve over time, and your frontend team will eventually demand additional data being sent over REST (or the same data in a different format). Do yourself a favour for the long run - create DTOs for everything you send via REST. Yes I know they're annoying, yes they impose a maintenance overhead, but they grant you the abillity to evolve your database and your REST interface independently. Just my 5 cents.

Collapse
 
giboow profile image
GiBoOw

Thanks for your feedback Martin.
I agree with you that it is better to use DTOs. That's what I do on big projects. It allows to better control the Inputs and to avoid problems when we make the code evolve.
But when I need an API for a small project and I want to go fast, I find it practical.