Skip to content

Use DTOs for Controllers #32

Description

@Anikate-De

Returning Domain level Models is bad. Really bad.

So bad that GPT4 says:

  1. Leaky Abstraction: Returning entities exposes the internal structure of the database, leading to a tightly coupled design, making it harder to change the schema without breaking the API.
  2. Security Risks: Entities might contain sensitive data that could accidentally be exposed, even with @JsonIgnore, increasing the risk of data leakage.
  3. Performance Overhead: Entities often include unnecessary fields and relationships, which may result in over-fetching data that is irrelevant for the client, leading to inefficiency.
  4. Serialization Issues: Entities might have complex relationships (e.g., bidirectional associations) that can lead to infinite loops during serialization, even with @JsonIgnore.
  5. Separation of Concerns: Using DTOs ensures that the API layer is separated from the persistence layer, promoting cleaner code and reducing unintended side effects during data transformation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions