Problem Statement
What is the safest default when returning objects from an API?
Explanation
Many leaks happen because APIs serialize entire objects. This can expose internal IDs, flags, and private data. A better pattern is to map data to a view model for each role and endpoint. Only include what a given caller needs.
This also makes change control easier. New internal fields do not leak by accident because the projection is explicit.
Code Solution
SolutionRead Only
// Good: map to view
{ "id": 123, "name": "Ana", "plan": "pro" }