Say I've got an object User:
@JsonView(User.Activity.class)
String name
@JsonView(User.Activity.class)
int id
String description;
// Realistically there will be a lot more fiels here...
... getters and setters
And I've then gone and created one:
User u = new User();
u.setName("xoxo");
u.setId(1);
u.setDescription("DESCRIPTION....");
dao.save(u);
return u.withJsonView(User.Activity.class); // Is there a way to apply this?
I want to return this object to the client with the fields from a specific JsonView
. How can I do this?
Edit
Hashmap hm = new Hashmap();
MappingJacksonValue value = new MappingJacksonValue(user);
value.setSerializationView(User.Activity.class);
hm.put("success", value);
return ResponseEntity.ok(hm); // Returns whole user object :\
That is all I'm doing. value ends up being the whole user object, even though I've only put the User.activity.class
view on a couple of fields. I'm then simply returning the hashmap in a responseentity