Reputation: 2062
I am working on a restful API. I am looking for a solution that "locks" the structure for a version, to satisfy the REST versioning.
For my project I use JAX-RS and JPA. My JPA entities can change quite often, but I don't want to have those changes automatically being exposed. I know a solution can be DTO (Data Transfer Ojbect), this will add a lot of classes and I am not sure if it is worth the investement.
Are there better/simpler solutions for achieving this, or is DTO the only way to go?
Upvotes: 0
Views: 566
Reputation: 8926
Put simply, yes, DTO is the way to go. That's a way to make your API and model independent. What's more sometimes there are situations where model (JPA) classes just can't be exposed via REST API (eg. if you have circular object dependencies). Maybe at the beginning DTO looks like overhead, it's the only way to keep model clean (ie. presentation layer agnostic - assuming REST is kind of way of presenting the model). Exposing a class via RESTful API often requires adding some specific annotations to the model. Having them in model directly would just pollute it.
Upvotes: 4