0

As far I know, Spring MVC allows to bind objects like that:

@RequestMapping(...)
public void doSmth(MyObject obj) {
// All MyObject's fields are filled now
}

But does there exists an elegant solution, which allows to bind the only specific fields?

For example, class User may possible contain private information such as registration timestamp which could be easily replaced by 3d-party side in case of using common object binding.

So needed is smth like:

class User {

   public String nick; <-- wanna bind this
   public String pass; <-- and this
   public Calendar timestamp; <-- but not this
   ...
}

Any ideas?

1 Answer 1

1

Try with data binder initialization.

For example using @InitBinder annotation in the controller:

@InitBinder
public void initBinder(WebDataBinder binder) {
  binder.setDisallowedFields("timestamp"); 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.