{"id":82464,"date":"2018-10-05T07:00:34","date_gmt":"2018-10-05T04:00:34","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=82464"},"modified":"2018-10-04T19:15:23","modified_gmt":"2018-10-04T16:15:23","slug":"how-bind-requestparam-object-spring","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html","title":{"rendered":"How to bind @RequestParam to object in Spring"},"content":{"rendered":"<p>Do you have multiple parameters annotated with <i>@RequestParam<\/i> in a request mapping method and feel it isn\u2019t readable?<\/p>\n<p>The annotation looks pretty straightforward when there\u2019s one or two input parameters expected in a request but when the list gets longer you might feel overwhelmed.<\/p>\n<p>You cannot use the <i>@RequestParam<\/i> annotation inside objects but it doesn\u2019t mean you\u2019re left with no other solution. In this post, I\u2019m going to show you <b>how to replace multiple @RequestParams with an object<\/b>.<ins><\/ins><\/p>\n<h2>1. Too long list of @RequestParams<\/h2>\n<p>No matter it\u2019s a controller or another class I believe you agree that <b>a long list of method parameters is hard to read<\/b>. In addition, if parameter types are the same, it\u2019s easier to make a mistake.<\/p>\n<p>Static code analysis tools like <a href=\"http:\/\/checkstyle.sourceforge.net\/config_sizes.html#ParameterNumber\">Checkstyle can detect numerous inputs in methods<\/a> because it\u2019s widely considered as a bad practice.<\/p>\n<p>It\u2019s very common that you pass a group of parameters together to different layers of your application. Such group usually can <b>form an object<\/b> and all you have to do is to <b>extract it and give it a proper name<\/b>.<\/p>\n<p>Let\u2019s take a look at a sample GET endpoint used to search for some products:<\/p>\n<pre class=\"brush:java\">@RestController\r\n@RequestMapping(\"\/products\")\r\nclass ProductController {\r\n\r\n   \/\/...\r\n\r\n   @GetMapping\r\n   List&lt;Product&gt; searchProducts(@RequestParam String query,\r\n                                @RequestParam(required = false, defaultValue = \"0\") int offset,\r\n                                @RequestParam(required = false, defaultValue = \"10\") int limit) {\r\n       return productRepository.search(query, offset, limit);\r\n   }\r\n\r\n}<\/pre>\n<p>Three parameters isn\u2019t a concerning number but it can easily grow. For instance, searching usually includes a sort order or some additional filters. In this case, they are all passed to the data access layer so they seem to be perfect candidates for <a href=\"https:\/\/refactoring.com\/catalog\/introduceParameterObject.html\">parameter object<\/a> extraction.<\/p>\n<h2>2. Binding @RequestParam to POJO<\/h2>\n<p>From my experience, developers don\u2019t replace long lists of <i>@RequestParams<\/i> because they simply aren\u2019t aware it\u2019s possible. The documentation of <i>@RequestParam<\/i> doesn\u2019t mention the alternative solution.<\/p>\n<p>Start with updating controller\u2019s method to accept a POJO as the input instead of the list of parameters.<\/p>\n<pre class=\"brush:java\">@GetMapping\r\nList&lt;Product&gt; searchProducts(ProductCriteria productCriteria) {\r\n   return productRepository.search(productCriteria);\r\n}<\/pre>\n<p>The POJO doesn\u2019t require any additional annotations. It should have a list of fields which match with request parameters that will be bound from the HTTP request, standard getters\/setters, and a no-argument constructor.<\/p>\n<pre class=\"brush:java\">class ProductCriteria {\r\n\r\n   private String query;\r\n   private int offset;\r\n   private int limit;\r\n\r\n   ProductCriteria() {\r\n   }\r\n\r\n   public String getQuery() {\r\n       return query;\r\n   }\r\n\r\n   public void setQuery(String query) {\r\n       this.query = query;\r\n   }\r\n\r\n   \/\/ other getters\/setters\r\n\r\n}<\/pre>\n<h3>2.1. Validating request parameters inside POJO<\/h3>\n<p>Alright, but we don\u2019t use the <i>@RequestParam<\/i> annotation only to bind HTTP parameters. Another useful feature of the annotation is the possibility to mark a given parameter as required. If the parameter is missing in a request, our endpoint can reject it.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>To achieve the same effect (and even much more!) with a POJO we may <b>use bean validation<\/b>. Java comes with numerous built-in contraints but you always <a href=\"http:\/\/dolszewski.com\/spring\/custom-validation-annotation-in-spring\/\">create a custom validation<\/a> if needed.<\/p>\n<p>Let\u2019s return to our POJO and add some validation rules to fields. If you just want to <b>mimic the behavior of <\/b><b><i>@RequestParam(required = false)<\/i><\/b>, all you need is the <b><i>@NotNull<\/i><\/b><b> annotation on a required field<\/b>.<\/p>\n<p>In many cases, it makes much more sense to use <i>@NotBlack<\/i> instead <i>@NotNull<\/i> as it also covers the undesired empty string problem (a string with the length of zero).<\/p>\n<pre class=\"brush:java\">final class ProductCriteria {\r\n\r\n   @NotBlank\r\n   private String query;\r\n   @Min(0)\r\n   private int offset;\r\n   @Min(1)\r\n   private int limi;\r\n\r\n   \/\/ ...\r\n\r\n}<\/pre>\n<p>A word of caution:<\/p>\n<p><b>Adding validation annotations of fields isn\u2019t enough to make it work.<\/b><\/p>\n<p>You also need to mark the POJO parameter in controller\u2019s method with the <i>@Valid<\/i> annotation. This way you inform Spring that it should execute validation on the binding step.<\/p>\n<pre class=\"brush:java\">@GetMapping\r\nList&lt;Product&gt; searchProducts(@Valid ProductCriteria productCriteria) {\r\n   \/\/ ...\r\n}<\/pre>\n<h3>2.2. Default request parameter values inside POJO<\/h3>\n<p>Another useful feature of the <i>@RequestParam<\/i> annotation is the ability to define the default value when the parameter isn\u2019t present it the HTTP request.<\/p>\n<p>When we have a POJO no special magic is needed. You just assign the default value directly to a field. When the parameter is missing in the request, nothing will override the predefined value.<\/p>\n<pre class=\"brush:java\">private int offset = 0;\r\nprivate int limit = 10;<\/pre>\n<h2>3. Multiple objects<\/h2>\n<p>You aren\u2019t forced to put all HTTP parameters inside a single object. You can group parameters in several POJOs.<\/p>\n<p>To illustrate that, let\u2019s add sort criteria to our endpoint. First, we need a separate object. Just like before it has some validation constraints.<\/p>\n<pre class=\"brush:java\">final class SortCriteria {\r\n\r\n   @NotNull\r\n   private SortOrder order;\r\n   @NotBlank\r\n   private String sortAttribute;\r\n\r\n   \/\/ constructor, getters\/setters\r\n\r\n}<\/pre>\n<p>In the controller, you just add it as a separate input parameter. Note that the <i>@Valid<\/i> annotation is required on each parameter which should be validated.<\/p>\n<pre class=\"brush:java\">@GetMapping\r\nList&lt;Product&gt; searchProducts(@Valid ProductCriteria productCriteria, @Valid SortCriteria sortCriteria) {\r\n   \/\/ ...\r\n}<\/pre>\n<h2>4. Nested objects<\/h2>\n<p>As an alternative to multiple input request objects we can also use composition. Parameter binding also works with nested objects.<\/p>\n<p>Below you can find an example in which the previously introduced sort criteria was moved to the product criteria POJO.<\/p>\n<p>To verify all nested properties, you should add the <i>@Valid<\/i> annotation to the field. Be aware that if the field is null Spring won\u2019t validate its properties. That might be the desired solution if all nested properties are optional. If not, just put the <i>@NotNull<\/i> annotation on that nested object field.<\/p>\n<pre class=\"brush:java\">final class ProductCriteria {\r\n\r\n   @NotNull\r\n   @Valid\r\n   private SortCriteria sort;\r\n\r\n   \/\/ ...\r\n\r\n}<\/pre>\n<p>HTTP parameters must match field names using the dot notation. In our case they should look as follows:<\/p>\n<pre class=\"brush:java\">sort.order=ASC&amp;sort.attribute=name<\/pre>\n<h2>5. Immutable DTO<\/h2>\n<p>Nowadays, you can observe a tendency in going away from traditional POJOs with setters in favor of immutable objects.<\/p>\n<p>Immutable objects have several benefits (and downsides as well \u2026 but shh). In my opinion, the biggest one is <b>simpler maintenance<\/b>.<\/p>\n<p>Have you ever been tracking through dozens of layers of your application to understand what conditions lead to a particular state of an object? In which place this or that field changed? Why is it updated? The name of a setter method doesn\u2019t explain anything. Setters have no meaning.<\/p>\n<p>Considering the fact when Spring framework was created, no one should be surprised that Spring strongly relies on POJO specification. Yet, times changed and old patterns became antipatterns.<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/old-pattern.jpeg\"><img decoding=\"async\" class=\"aligncenter wp-image-82468 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/old-pattern.jpeg\" alt=\"@RequestParam\" width=\"640\" height=\"430\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/old-pattern.jpeg 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/10\/old-pattern-300x202.jpeg 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>There\u2019s no easy way to magically bind HTTP arguments to a POJO using a parameterized constructor. The non-argument constructor is inevitable. However, we can make that constructor <i>private<\/i> (but sadly not in nested objects) and removed all setters. From the public perspective, the object will become immutable.<\/p>\n<p>By default, Spring requires setter methods to bind HTTP parameters to fields. Fortunately, it\u2019s possible to reconfigure the binder and use direct field access (via reflection).<\/p>\n<p>In order to configure the data binder globally for your whole application, you can create a controller advice component. You can alter the binder configuration inside a method annotated with the <i>@InitBinder<\/i> annotation which accepts the binder as an input.<\/p>\n<pre class=\"brush:java\">@ControllerAdvice\r\nclass BindingControllerAdvice {\r\n\r\n   @InitBinder\r\n   public void initBinder(WebDataBinder binder) {\r\n       binder.initDirectFieldAccess();\r\n   }\r\n\r\n}<\/pre>\n<p>After creating that small class we can return to our POJO and remove all setter methods from the class to make it read-only for the public use.<\/p>\n<pre class=\"brush:java\">final class ProductCriteria {\r\n\r\n   @NotBlank\r\n   private String query;\r\n   @Min(0)\r\n   private int offset = 0;\r\n   @Min(1)\r\n   private int limit = 10;\r\n\r\n   private ProductCriteria() {\r\n   }\r\n\r\n   public String getQuery() {\r\n       return query;\r\n   }\r\n\r\n   public int getOffset() {\r\n       return offset;\r\n   }\r\n\r\n   public int getLimit() {\r\n       return limit;\r\n   }\r\n\r\n}<\/pre>\n<p>Restart your application and play around with the parameters of the HTTP request. It should work as before.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, you could see that HTTP request parameters bound in Spring MVC controllers using <i>@RequestParam<\/i> can be easily replaced with a parameter object which groups several attributes and is nothing more than a simple POJO or optionally an immutable DTO.<\/p>\n<p>You can <a href=\"https:\/\/github.com\/danielolszewski\/blog\/tree\/master\/spring-requestparam-object\">find described samples in the GitHub repository<\/a>. I hope presented cases are self-explanatory but if there are any doubts or you would like to put your two cents in, I strongly encourage you to leave your comment below the post.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>Published on Java Code Geeks with permission by Daniel Olszewski, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener\">JCG program<\/a>. See the original article here: <a href=\"http:\/\/dolszewski.com\/spring\/how-to-bind-requestparam-to-object\/\" target=\"_blank\" rel=\"noopener\">How to bind @RequestParam to object in Spring<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Do you have multiple parameters annotated with @RequestParam in a request mapping method and feel it isn\u2019t readable? The annotation looks pretty straightforward when there\u2019s one or two input parameters expected in a request but when the list gets longer you might feel overwhelmed. You cannot use the @RequestParam annotation inside objects but it doesn\u2019t &hellip;<\/p>\n","protected":false},"author":3861,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[815,30,854],"class_list":["post-82464","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-rest","tag-spring","tag-spring-boot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to bind @RequestParam to object in Spring - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about @RequestParam? Check our article explaining how to replace multiple annotations @RequestParams with an object.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to bind @RequestParam to object in Spring - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about @RequestParam? Check our article explaining how to replace multiple annotations @RequestParams with an object.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-05T04:00:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Daniel Olszewski\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@daolszewski\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daniel Olszewski\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html\"},\"author\":{\"name\":\"Daniel Olszewski\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/f2727a76059a91188524de49e1e397fb\"},\"headline\":\"How to bind @RequestParam to object in Spring\",\"datePublished\":\"2018-10-05T04:00:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html\"},\"wordCount\":1191,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"REST\",\"Spring\",\"Spring Boot\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html\",\"name\":\"How to bind @RequestParam to object in Spring - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2018-10-05T04:00:34+00:00\",\"description\":\"Interested to learn about @RequestParam? Check our article explaining how to replace multiple annotations @RequestParams with an object.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/10\\\/how-bind-requestparam-object-spring.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"How to bind @RequestParam to object in Spring\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/f2727a76059a91188524de49e1e397fb\",\"name\":\"Daniel Olszewski\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g\",\"caption\":\"Daniel Olszewski\"},\"description\":\"Daniel Olszewski is a software developer passionate about the JVM ecosystem and web development. He is an advocate of clean, maintainable, and well tested code\",\"sameAs\":[\"http:\\\/\\\/dolszewski.com\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/olszewskidaniel\\\/\",\"https:\\\/\\\/x.com\\\/daolszewski\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/daniel-olszewski\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to bind @RequestParam to object in Spring - Java Code Geeks","description":"Interested to learn about @RequestParam? Check our article explaining how to replace multiple annotations @RequestParams with an object.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html","og_locale":"en_US","og_type":"article","og_title":"How to bind @RequestParam to object in Spring - Java Code Geeks","og_description":"Interested to learn about @RequestParam? Check our article explaining how to replace multiple annotations @RequestParams with an object.","og_url":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-10-05T04:00:34+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Daniel Olszewski","twitter_card":"summary_large_image","twitter_creator":"@daolszewski","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Daniel Olszewski","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html"},"author":{"name":"Daniel Olszewski","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/f2727a76059a91188524de49e1e397fb"},"headline":"How to bind @RequestParam to object in Spring","datePublished":"2018-10-05T04:00:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html"},"wordCount":1191,"commentCount":2,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["REST","Spring","Spring Boot"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html","url":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html","name":"How to bind @RequestParam to object in Spring - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2018-10-05T04:00:34+00:00","description":"Interested to learn about @RequestParam? Check our article explaining how to replace multiple annotations @RequestParams with an object.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2018\/10\/how-bind-requestparam-object-spring.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"How to bind @RequestParam to object in Spring"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/f2727a76059a91188524de49e1e397fb","name":"Daniel Olszewski","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/478137d4c1cdb34323c29f65310308ecaabeb98e1efdf179d47932b1ddb219d3?s=96&d=mm&r=g","caption":"Daniel Olszewski"},"description":"Daniel Olszewski is a software developer passionate about the JVM ecosystem and web development. He is an advocate of clean, maintainable, and well tested code","sameAs":["http:\/\/dolszewski.com","https:\/\/www.linkedin.com\/in\/olszewskidaniel\/","https:\/\/x.com\/daolszewski"],"url":"https:\/\/www.javacodegeeks.com\/author\/daniel-olszewski"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/82464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/3861"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=82464"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/82464\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=82464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=82464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=82464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}