Reputation: 521
I have a MongoDB which stores user information including the user's password. Users can call a GET request to retrieve all the user's information from the database. But I do not want the client to see the password, just every thing else.
Here, the client can get a user's personal info provided he has his username:
/* Get user by username */
@RequestMapping(method=RequestMethod.GET, value="/getByUsername")
public @ResponseBody User getUserByUsername(@RequestParam("username") String username) {
return repo.findByUsername(username);
}
the returned statement is in a JSON format like this:
{ id: "559e8d522de3b3e03b06457c" firstname: "bob" lastname: "alice" username: "username" password: "testpassword" address: "2020 america road" city: "The City" state: "maryland" zipCode: "99999" phoneNumber: "3421345" email: "[email protected]" }
This is what is being sent to the client and what the client sees. But I want to omit the password field from this JSON document.
How do I do that?
Upvotes: 1
Views: 113