{"id":28489,"date":"2014-07-31T19:00:04","date_gmt":"2014-07-31T16:00:04","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=28489"},"modified":"2014-07-31T07:08:28","modified_gmt":"2014-07-31T04:08:28","slug":"spring-4-1-and-java-8-java-util-optional","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html","title":{"rendered":"Spring 4.1 and Java 8: java.util.Optional"},"content":{"rendered":"<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logo-spring-io.png\"><img decoding=\"async\" class=\"alignright size-medium wp-image-28528\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logo-spring-io-300x94.png\" alt=\"logo-spring-io\" width=\"300\" height=\"94\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logo-spring-io-300x94.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/logo-spring-io.png 352w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nAs of Spring 4.1 Java 8\u2019s <code>java.util.Optional<\/code>, a container object which may or may not contain a non-null value, is supported with <code>@RequestParam<\/code>, <code>@RequestHeader<\/code> and <code>@MatrixVariable<\/code>. While using Java 8\u2019s <code>java.util.Optional<\/code> you make sure your parameters are never <code>null<\/code>.<\/p>\n<p>&nbsp;<br \/>\n&nbsp;<\/p>\n<h2>Request Params<\/h2>\n<p>In this example we will bind <code>java.time.LocalDate<\/code> as <code>java.util.Optional<\/code> using <code>@RequestParam<\/code>:<\/p>\n<pre class=\" brush:java\">@RestController\r\n@RequestMapping(\"o\")\r\npublic class SampleController {\r\n\r\n    @RequestMapping(value = \"r\", produces = \"text\/plain\")\r\n    public String requestParamAsOptional(\r\n            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)\r\n            @RequestParam(value = \"ld\") Optional&lt;LocalDate&gt; localDate) {\r\n\r\n        StringBuilder result = new StringBuilder(\"ld: \");\r\n        localDate.ifPresent(value -&gt; result.append(value.toString()));\r\n        return result.toString();\r\n    }\r\n}<\/pre>\n<p>Prior to Spring 4.1, we would get an exception that no matching editors or conversion strategy was found. As of Spring 4.1, this is no more an issue. To verify the binding works properly, we may create a simple integration test:<\/p>\n<pre class=\" brush:java\">@RunWith(SpringJUnit4ClassRunner.class)\r\n@SpringApplicationConfiguration(classes = Application.class)\r\n@WebAppConfiguration\r\npublic class SampleSomeControllerTest {\r\n\r\n    @Autowired\r\n    private WebApplicationContext wac;\r\n    private MockMvc mockMvc;\r\n\r\n    @Before\r\n    public void setUp() throws Exception {\r\n        mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();\r\n    }\r\n\r\n    \/\/ ...\r\n\r\n}<\/pre>\n<p>In the first test, we will check if the binding works properly and if the proper result is returned:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\" brush:java\">@Test\r\npublic void bindsNonNullLocalDateAsRequestParam() throws Exception {\r\n    mockMvc.perform(get(\"\/o\/r\").param(\"ld\", \"2020-01-01\"))\r\n            .andExpect(content().string(\"ld: 2020-01-01\"));\r\n}<\/pre>\n<p>In the next test, we will not pass <code>ld<\/code> parameter:<\/p>\n<pre class=\" brush:java\">@Test\r\npublic void bindsNoLocalDateAsRequestParam() throws Exception {\r\n    mockMvc.perform(get(\"\/o\/r\"))\r\n            .andExpect(content().string(\"ld: \"));\r\n}<\/pre>\n<p>Both tests should be green!<\/p>\n<h2>Request Headers<\/h2>\n<p>Similarly, we can bind <code>@RequestHeader<\/code> to <code>java.util.Optional<\/code>:<\/p>\n<pre class=\" brush:java\">@RequestMapping(value = \"h\", produces = \"text\/plain\")\r\npublic String requestHeaderAsOptional(\r\n        @RequestHeader(value = \"Custom-Header\") Optional&lt;String&gt; header) {\r\n\r\n    StringBuilder result = new StringBuilder(\"Custom-Header: \");\r\n    header.ifPresent(value -&gt; result.append(value));\r\n\r\n    return result.toString();\r\n}<\/pre>\n<p>And the tests:<\/p>\n<pre class=\" brush:java\">@Test\r\npublic void bindsNonNullCustomHeader() throws Exception {\r\n    mockMvc.perform(get(\"\/o\/h\").header(\"Custom-Header\", \"Value\"))\r\n            .andExpect(content().string(\"Custom-Header: Value\"));\r\n}\r\n\r\n@Test\r\npublic void noCustomHeaderGiven() throws Exception {\r\n    mockMvc.perform(get(\"\/o\/h\").header(\"Custom-Header\", \"\"))\r\n            .andExpect(content().string(\"Custom-Header: \"));\r\n}<\/pre>\n<h2>Matrix Variables<\/h2>\n<p>Introduced in Spring 3.2 <code>@MatrixVariable<\/code> annotation indicates that a method parameter should be bound to a name-value pair within a path segment:<\/p>\n<pre class=\" brush:java\">@RequestMapping(value = \"m\/{id}\", produces = \"text\/plain\")\r\npublic String execute(@PathVariable Integer id,\r\n                      @MatrixVariable Optional&lt;Integer&gt; p,\r\n                      @MatrixVariable Optional&lt;Integer&gt; q) {\r\n\r\n    StringBuilder result = new StringBuilder();\r\n    result.append(\"p: \");\r\n    p.ifPresent(value -&gt; result.append(value));\r\n    result.append(\", q: \");\r\n    q.ifPresent(value -&gt; result.append(value));\r\n\r\n    return result.toString();\r\n}<\/pre>\n<p>The above method can be called via <code>\/o\/m\/42;p=4;q=2<\/code> url. Let\u2019s create a test for that:<\/p>\n<pre class=\" brush:java\">@Test\r\npublic void bindsNonNullMatrixVariables() throws Exception {\r\n    mockMvc.perform(get(\"\/o\/m\/42;p=4;q=2\"))\r\n            .andExpect(content().string(\"p: 4, q: 2\"));\r\n}<\/pre>\n<p>Unfortunatelly, the test will fail, because support for <code>@MatrixVariable<\/code> annotation is <strong>disabled by default in Spring MVC<\/strong>. In order to enable it we need to tweak the configuration and set the <code>removeSemicolonContent<\/code> property of <code>RequestMappingHandlerMapping<\/code> to <code>false<\/code>. By default it is set to <code>true<\/code>. I have done with <code>WebMvcConfigurerAdapter<\/code> like below:<\/p>\n<pre class=\" brush:java\">@Configuration\r\npublic class WebMvcConfig extends WebMvcConfigurerAdapter {\r\n    @Override\r\n    public void configurePathMatch(PathMatchConfigurer configurer) {\r\n        UrlPathHelper urlPathHelper = new UrlPathHelper();\r\n        urlPathHelper.setRemoveSemicolonContent(false);\r\n        configurer.setUrlPathHelper(urlPathHelper);\r\n    }\r\n}<\/pre>\n<p>And now all tests passes! Please find the source code for this article here: <a href=\"https:\/\/github.com\/kolorobot\/spring41-samples\">https:\/\/github.com\/kolorobot\/spring41-samples<\/a><\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/blog.codeleak.pl\/2014\/07\/Spring41-and-Java8-Optional-as-RequestParam-RequestHeader-MatrixVariable.html\">Spring 4.1 and Java 8: java.util.Optional<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Rafal Borowiec at the <a href=\"http:\/\/blog.codeleak.pl\/\">Codeleak.pl<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>As of Spring 4.1 Java 8\u2019s java.util.Optional, a container object which may or may not contain a non-null value, is supported with @RequestParam, @RequestHeader and @MatrixVariable. While using Java 8\u2019s java.util.Optional you make sure your parameters are never null. &nbsp; &nbsp; Request Params In this example we will bind java.time.LocalDate as java.util.Optional using @RequestParam: @RestController &hellip;<\/p>\n","protected":false},"author":516,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[196,30],"class_list":["post-28489","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-java-8","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring 4.1 and Java 8: java.util.Optional<\/title>\n<meta name=\"description\" content=\"As of Spring 4.1 Java 8\u2019s java.util.Optional, a container object which may or may not contain a non-null value, is supported with @RequestParam,\" \/>\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\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring 4.1 and Java 8: java.util.Optional\" \/>\n<meta property=\"og:description\" content=\"As of Spring 4.1 Java 8\u2019s java.util.Optional, a container object which may or may not contain a non-null value, is supported with @RequestParam,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.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=\"2014-07-31T16:00:04+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=\"Rafal Borowiec\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/kolorobot\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rafal Borowiec\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.html\"},\"author\":{\"name\":\"Rafal Borowiec\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/b1a0b2657d5dd2459806446ac66d2d52\"},\"headline\":\"Spring 4.1 and Java 8: java.util.Optional\",\"datePublished\":\"2014-07-31T16:00:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.html\"},\"wordCount\":252,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Java 8\",\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.html\",\"name\":\"Spring 4.1 and Java 8: java.util.Optional\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2014-07-31T16:00:04+00:00\",\"description\":\"As of Spring 4.1 Java 8\u2019s java.util.Optional, a container object which may or may not contain a non-null value, is supported with @RequestParam,\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.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\\\/2014\\\/07\\\/spring-4-1-and-java-8-java-util-optional.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\":\"Spring 4.1 and Java 8: java.util.Optional\"}]},{\"@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\\\/b1a0b2657d5dd2459806446ac66d2d52\",\"name\":\"Rafal Borowiec\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g\",\"caption\":\"Rafal Borowiec\"},\"description\":\"Software developer, Team Leader, Agile practitioner, occasional blogger, lecturer. Open Source enthusiast, quality oriented and open-minded.\",\"sameAs\":[\"http:\\\/\\\/blog.codeleak.pl\\\/\",\"http:\\\/\\\/pl.linkedin.com\\\/in\\\/borowiec\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/kolorobot\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/rafal-borowiec\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring 4.1 and Java 8: java.util.Optional","description":"As of Spring 4.1 Java 8\u2019s java.util.Optional, a container object which may or may not contain a non-null value, is supported with @RequestParam,","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\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html","og_locale":"en_US","og_type":"article","og_title":"Spring 4.1 and Java 8: java.util.Optional","og_description":"As of Spring 4.1 Java 8\u2019s java.util.Optional, a container object which may or may not contain a non-null value, is supported with @RequestParam,","og_url":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-07-31T16:00:04+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":"Rafal Borowiec","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/kolorobot","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Rafal Borowiec","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html"},"author":{"name":"Rafal Borowiec","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/b1a0b2657d5dd2459806446ac66d2d52"},"headline":"Spring 4.1 and Java 8: java.util.Optional","datePublished":"2014-07-31T16:00:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html"},"wordCount":252,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Java 8","Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html","url":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html","name":"Spring 4.1 and Java 8: java.util.Optional","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2014-07-31T16:00:04+00:00","description":"As of Spring 4.1 Java 8\u2019s java.util.Optional, a container object which may or may not contain a non-null value, is supported with @RequestParam,","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/spring-4-1-and-java-8-java-util-optional.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\/2014\/07\/spring-4-1-and-java-8-java-util-optional.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":"Spring 4.1 and Java 8: java.util.Optional"}]},{"@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\/b1a0b2657d5dd2459806446ac66d2d52","name":"Rafal Borowiec","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g","caption":"Rafal Borowiec"},"description":"Software developer, Team Leader, Agile practitioner, occasional blogger, lecturer. Open Source enthusiast, quality oriented and open-minded.","sameAs":["http:\/\/blog.codeleak.pl\/","http:\/\/pl.linkedin.com\/in\/borowiec\/","https:\/\/x.com\/https:\/\/twitter.com\/kolorobot"],"url":"https:\/\/www.javacodegeeks.com\/author\/rafal-borowiec"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/28489","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\/516"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=28489"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/28489\/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=28489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=28489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=28489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}