We are doing a similar thing in our application, and we found it useful to separate database entity objects and have another class group for JSON output.
If you use a JSON framework that simply checks your object and pulls out some JSON for each property of the object, then it can have objects such as:
PersonEntity - a class controlled by JPA and also PersonJsonOutput - a class specifically designed for JSON output
In the long run, it can be safer. This allows you to have database changes that are not automatically reflected in your JSON service, you might want to change your JSON service, perhaps instead of breaking old versions as soon as your database object changes.
It also gives you more control over your JSON output in terms of date formats or forcing numbers in the database as strings in your JSON, etc.
This answer really depends on how you create your JSON, but it looks like your library is doing some introspection.
Kieran
source share