Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
It is best if you avoid this altogether. You shouldn't expose your entities directly to the outside world since there is always a chance that your entity contains a proxy object which can mess up the serialization/deserialization process. You may also end up with entity classes that are bloated with annotations. You should define a separate class with every field that needs to be seen/set from the outside and expose it through your APIs. This class is usually called AccountDTO or just Account if your entities' names end with "Entity" (AccountEntity, for example). If you don't like writing boilerplate converters between DTOs and entities, check out MapStruct. An annotation processor library (similar to Lombok, which you are currently using) that provides methods that can simplify conversion between Java classes and beans.