java - How to work with multiple 'views' of the same domain model? -
i'm using jackson parse json android app. intend use in rest server too, i'll sharing models between client , server.
i've created pojo model domain object "friend". when client gets https://www.myserver.com/api/1/friend/1234 want return serialised friend id 1234, perhaps 1 or 2 fields missing.
however, when client gets https://www.myserver.com/api/1/friend/ want return friend objects, less data might more appropriate search results (e.g. first name, last name , profile image, excluding list of friends, date of birth, etc.).
what pattern should follow here can represent same underlying model in different ways depending on how it'll accessed?
inheritance can option in conjunction @jsonignoreproperties
.
you can have class friend
, extend restrict properties serialized.
@jsonignoreproperties({ "friends", "dateofbirth" }) class restrictedfriend extends friend { }
Comments
Post a Comment