Spring MVC Complex object as GET @RequestParam
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In Spring MVC, a complex object passed through a GET request is usually not something you handle with one @RequestParam string. If the query string contains multiple fields, the normal solution is model binding with @ModelAttribute or even a plain method parameter, not a single @RequestParam Person person.
@RequestParam is great for simple scalar values. For multi-field request data such as name, age, and city, Spring's object binding is usually the cleaner and more idiomatic approach.
Bind Query Parameters Into an Object
Suppose the request looks like this:
Define a simple DTO:
Then bind it in the controller:
Spring matches query parameters to bean properties by name and populates the object automatically.
You Often Do Not Need @ModelAttribute Explicitly
For many GET handlers, this also works:
Spring will still treat it as a model attribute in this context. Adding @ModelAttribute can make the intent clearer, but the binding mechanism is the same.
When @RequestParam Still Makes Sense
If the request really contains a single encoded value, then @RequestParam may be appropriate:
In that case, Spring sees one string parameter named person, so you need a converter to turn that string into an object:
That is a valid pattern, but it solves a different problem. It is for one encoded parameter, not ordinary multi-field query binding.
Validation Still Applies
Complex GET filters often need validation just like POST bodies do:
Then validate it in the controller with @Valid if needed. GET requests are still user input and can still contain malformed values.
Common Pitfalls
The biggest mistake is trying to use one @RequestParam for a multi-field object when the query string already exposes separate fields. In that case, use object binding, not one large string.
Another common issue is forgetting that binding by property name requires matching parameter names. If the query string says fullName but the DTO says name, binding will not happen automatically.
Developers also sometimes use a converter when plain @ModelAttribute binding would have been simpler and more readable.
Finally, do not forget validation and optionality. A complex object in a GET request still needs rules for missing or invalid parameters.
Summary
- For multi-field GET query strings, bind to a complex object with
@ModelAttributeor a plain object parameter. - Use
@RequestParamfor simple scalar parameters or for one explicitly encoded string value. - Add a custom converter only when one query parameter must be parsed into an object.
- Make sure query parameter names match the target object's property names.
- Treat complex GET input as real user input and validate it when appropriate.

