Avoid exposing JPA entities in REST API, Instead generate client beans using OpenAPI Generator and map them to entities using MapStruct.

Ravinder Thirumala
4 min readApr 15, 2020

There’s always been discussion about whether we should expose JPA entities in RESTful APIs, or define Data Transfer Objects(DTOs) and map entity classes to the DTOs. We will discuss pros and cons of exposing JPA entities as REST API resources.

We will see how to generate REST API DTOs from Open API Specification using openapi-generator tools and also how to greatly simplify mapping between JPA entities…

--

--