1

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: "pasdf@test.com" }

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?

Viratan
  • 503
  • 3
  • 9
  • 19
  • You can have a look this in [link](http://stackoverflow.com/questions/23101260/ignore-fields-from-java-object-dynamically-while-sending-as-json-from-spring-mvc) – yas Jul 09 '15 at 16:57

1 Answers1

1

Mark the getter for password with @JsonIgnore.

Sam Berry
  • 7,394
  • 6
  • 40
  • 58