Let's say if I have an Entity
named person with lots of information including SSN. When other user query this person, I want to show a 'lite' version of person Entity
. I could've done so by annotating SSN with @Transient
, but that means the person himself would not get this field too. Is it possible to reuse the same Entity
but return two different json to client? I'm using spring boot.
Asked
Active
Viewed 1,275 times
1

user1865027
- 3,505
- 6
- 33
- 71
-
that's what `data transfer objects` are for. See also: https://stackoverflow.com/questions/1051182/what-is-data-transfer-object – fateddy Sep 03 '17 at 08:41
1 Answers
0
First of all @Transient
just means that the value, the SSN in your case, won't be persisted to the database.
As for your problem annotations are static and cannot be applied dynamically.
You have 2 Options:
- Define a new View class for your user.
- Look at JacksonJsonViews

ketrox
- 889
- 1
- 12
- 23