{"id":56504,"date":"2016-05-23T10:00:05","date_gmt":"2016-05-23T07:00:05","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=56504"},"modified":"2016-05-22T11:52:51","modified_gmt":"2016-05-22T08:52:51","slug":"content-negotiation-spring-framework","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html","title":{"rendered":"Content Negotiation in Spring Framework"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>With what we had done with\u00a0<a href=\"https:\/\/www.javacodegeeks.com\/2016\/03\/configure-multiple-view-resolvers-spring.html\" target=\"_blank\"><strong>BeanNameViewResolver<\/strong><\/a>, is that we just had created multiple bean views in Spring context to generate the expected output. Spring soon introduced the <strong>Content Negotiation strategy<\/strong>, where we can use the traditional RESTful\u00a0<strong>@ResponseBody<\/strong>\u00a0approach\u00a0and HTTP message converters, to return desired outputs in\u00a0JSON or XML, along with some flexibility and dynamicity it provides with\u00a0the configuration.<\/p>\n<p>Often we need to provide multiple representations (or views) of the same data returned by the controller. This is very elegantly achieved with Content negotiation in Spring.<\/p>\n<h2>2. Implementation<\/h2>\n<p>To quickly start with the implementation, lets first create a new maven project. <a href=\"http:\/\/www.jcombat.com\/spring\/spring-mvc-with-maven\" target=\"_blank\">Click here to get help on creating your new maven project in Eclipse<\/a><\/p>\n<p>Let\u2019s now add the\u00a0needed dependencies to the <strong>pom.xml <\/strong>file.<\/p>\n<p><em>pom.xml<\/em><\/p>\n<pre class=\"brush:xml\">&lt;!-- Spring dependencies --&gt;\r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;spring-core&lt;\/artifactId&gt;\r\n\t&lt;version&gt;4.2.1.RELEASE&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n \r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;spring-web&lt;\/artifactId&gt;\r\n\t&lt;version&gt;4.2.1.RELEASE&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n \r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;spring-webmvc&lt;\/artifactId&gt;\r\n\t&lt;version&gt;4.2.1.RELEASE&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n \r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;javax.xml.bind&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;jaxb-api&lt;\/artifactId&gt;\r\n\t&lt;version&gt;2.2.6&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;javax.xml&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;jaxb-impl&lt;\/artifactId&gt;\r\n\t&lt;version&gt;2.1&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n \r\n&lt;!-- Jackson JSON Processor --&gt;\r\n&lt;dependency&gt;\r\n\t&lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;jackson-databind&lt;\/artifactId&gt;\r\n\t&lt;version&gt;2.4.1&lt;\/version&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>Open <strong>web.xml<\/strong> and make sure you have the proper configuration done.<\/p>\n<p><em>web.xml<\/em><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"ISO-8859-1\"?&gt;\r\n&lt;web-app xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txmlns=\"http:\/\/java.sun.com\/xml\/ns\/javaee\"\r\n\txsi:schemaLocation=\"http:\/\/java.sun.com\/xml\/ns\/javaee\r\n\thttp:\/\/java.sun.com\/xml\/ns\/javaee\/web-app_2_5.xsd\"\r\n\tid=\"WebApp_ID\" version=\"2.5\"&gt;\r\n \r\n\t&lt;display-name&gt;SpringMVCWithContentNegotiation&lt;\/display-name&gt;\r\n \r\n\t&lt;servlet&gt;\r\n\t\t&lt;servlet-name&gt;mvc-dispatcher&lt;\/servlet-name&gt;\r\n\t\t&lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;\/servlet-class&gt;\r\n\t\t&lt;load-on-startup&gt;1&lt;\/load-on-startup&gt;\r\n\t&lt;\/servlet&gt;\r\n \r\n\t&lt;servlet-mapping&gt;\r\n\t\t&lt;servlet-name&gt;mvc-dispatcher&lt;\/servlet-name&gt;\r\n\t\t&lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\r\n\t&lt;\/servlet-mapping&gt;\r\n \r\n&lt;\/web-app&gt;<\/pre>\n<p>Create a new context file as <em>&lt;servlet name&gt;-servlet.xml<\/em>, which\u00a0has to be <strong>mvc-dispatcher-servlet.xml<\/strong>\u00a0with the following content.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><em>mvc-dispatcher-servlet.xml<\/em><\/p>\n<pre class=\"brush:xml\">&lt;beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\"\r\n\txmlns:context=\"http:\/\/www.springframework.org\/schema\/context\"\r\n\txmlns:mvc=\"http:\/\/www.springframework.org\/schema\/mvc\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/mvc http:\/\/www.springframework.org\/schema\/mvc\/spring-mvc.xsd\r\n\thttp:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.0.xsd http:\/\/www.springframework.org\/schema\/context \r\n        http:\/\/www.springframework.org\/schema\/context\/spring-context-3.0.xsd http:\/\/www.springframework.org\/schema\/mvc http:\/\/www.springframework.org\/schema\/mvc\/spring-mvc-3.0.xsd\"&gt;\r\n \r\n\t&lt;mvc:annotation-driven\r\n\t\tcontent-negotiation-manager=\"contentNegotiationManager\"&gt;\r\n\t\t&lt;mvc:path-matching registered-suffixes-only=\"true\" \/&gt;\r\n\t&lt;\/mvc:annotation-driven&gt;\r\n \r\n\t&lt;context:component-scan base-package=\"com.jcombat.controller\" \/&gt;\r\n \r\n\t&lt;!-- To disable path extension check in the path variable of URI --&gt;\r\n\t&lt;bean id=\"contentNegotiationManager\"\r\n\t\tclass=\"org.springframework.web.accept.ContentNegotiationManagerFactoryBean\"&gt;\r\n\t\t&lt;property name=\"favorPathExtension\" value=\"true\" \/&gt;\r\n\t\t&lt;property name=\"ignoreAcceptHeader\" value=\"true\" \/&gt;\r\n\t\t&lt;property name=\"useJaf\" value=\"false\"\/&gt;\r\n\t\t&lt;property name=\"defaultContentType\" value=\"application\/json\" \/&gt;\r\n\t\t&lt;property name=\"mediaTypes\"&gt;\r\n\t\t\t&lt;map&gt;\r\n\t\t\t\t&lt;entry key=\"json\" value=\"application\/json\" \/&gt;\r\n\t\t\t\t&lt;entry key=\"xml\" value=\"application\/xml\" \/&gt;\r\n\t\t\t&lt;\/map&gt;\r\n\t\t&lt;\/property&gt;\r\n\t&lt;\/bean&gt;\r\n \r\n\t&lt;!-- For Other media types --&gt;\r\n\t&lt;bean id=\"jspViewResolver\"\r\n\t\tclass=\"org.springframework.web.servlet.view.InternalResourceViewResolver\"&gt;\r\n\t\t&lt;property name=\"prefix\" value=\"\/WEB-INF\/jsp\/\" \/&gt;\r\n\t\t&lt;property name=\"suffix\" value=\".jsp\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n \r\n&lt;\/beans&gt;<\/pre>\n<blockquote>\n<p>Note that the component-scanning is applied only to com.jcombat.controller package, so Spring can auto-detect the application controller.<\/p>\n<\/blockquote>\n<p>When making an HTTP request, we can specify\u00a0what type of response we\u00a0would like to have by setting the <strong>Accept\u00a0<\/strong>header property.\u00a0But due to improper working of the browsers with Accept headers, we mostly prefer ignoring the Accept headers in a Spring based web applications, which returns output in formats other than the HTML.<\/p>\n<p>With <strong>Java Activation Framework<\/strong> (JAF), we don\u2019t need to explicitly specify the media type mappings, instead it gets implicitly done by\u00a0JAF. To use JAF, we might need to add an extra dependency of <strong>activation.jar<\/strong>. Probably we just want to support two output formats i.e. JSON and XML, therefore we are opting\u00a0out of it and rather\u00a0specifying the\u00a0media type mappings explicitly.<\/p>\n<p>It\u2019s now time to write the controller, which should be like specified below.<\/p>\n<p><em>EmployeeController.java<\/em><\/p>\n<pre class=\"brush:java\">package com.jcombat.controller;\r\n \r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.ResponseBody;\r\n \r\nimport com.jcombat.bean.Employee;\r\n \r\n@Controller\r\npublic class EmployeeController {\r\n \r\n\t@RequestMapping(value = \"\/employeeData\", method = RequestMethod.GET, produces={\"application\/xml\", \"application\/json\"})\r\n\tpublic @ResponseBody Employee getEmployee() {\r\n\t\tEmployee employee = new Employee();\r\n\t\temployee.setEmailId(\"abc@gmail.com\");\r\n\t\temployee.setEmpId(\"123\");\r\n\t\temployee.setName(\"Ajit\");\r\n\t\treturn employee;\r\n\t}\r\n}<\/pre>\n<h2>3. Useful Links<\/h2>\n<ul>\n<li><a href=\"http:\/\/www.jcombat.com\/spring\/spring-mvc-with-maven\" target=\"_blank\">Spring MVC integration with Maven<\/a><\/li>\n<li><a href=\"https:\/\/www.javacodegeeks.com\/2016\/03\/configure-multiple-view-resolvers-spring.html\" target=\"_blank\">Configure multiple View Resolvers in Spring<\/a><\/li>\n<\/ul>\n<h2>4. Running\u00a0the application<\/h2>\n<p>When we\u00a0run the application, below is what we see.<\/p>\n<p>JSON Output<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/json.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-56515\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/json.png\" alt=\"json\" width=\"688\" height=\"129\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/json.png 688w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/json-300x56.png 300w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<p>XML\u00a0Output<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/xml.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-56516\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/xml.png\" alt=\"xml\" width=\"629\" height=\"98\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/xml.png 629w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/xml-300x47.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/xml-620x98.png 620w\" sizes=\"(max-width: 629px) 100vw, 629px\" \/><\/a><\/p>\n<h2>5. Download the source code<\/h2>\n<p><a href=\"https:\/\/www.dropbox.com\/s\/nm96ze9s1hpacyk\/SpringMVCWithContentNegotiation.zip?dl=0\" target=\"_blank\">Download the source code<\/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:\/\/www.jcombat.com\/spring\/content-negotiation-in-spring\">Content Negotiation in Spring Framework<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/join-us\/jcg\/\">JCG partner<\/a> Abhimanyu Prasad at the <a href=\"http:\/\/www.jcombat.com\">jCombat<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction With what we had done with\u00a0BeanNameViewResolver, is that we just had created multiple bean views in Spring context to generate the expected output. Spring soon introduced the Content Negotiation strategy, where we can use the traditional RESTful\u00a0@ResponseBody\u00a0approach\u00a0and HTTP message converters, to return desired outputs in\u00a0JSON or XML, along with some flexibility and dynamicity &hellip;<\/p>\n","protected":false},"author":958,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30],"class_list":["post-56504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Content Negotiation in Spring Framework - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction With what we had done with\u00a0BeanNameViewResolver, is that we just had created multiple bean views in Spring context to generate the\" \/>\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\/2016\/05\/content-negotiation-spring-framework.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Content Negotiation in Spring Framework - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction With what we had done with\u00a0BeanNameViewResolver, is that we just had created multiple bean views in Spring context to generate the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.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:author\" content=\"https:\/\/www.facebook.com\/abhi435\" \/>\n<meta property=\"article:published_time\" content=\"2016-05-23T07:00:05+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=\"Abhimanyu Prasad\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abhimanyu Prasad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.html\"},\"author\":{\"name\":\"Abhimanyu Prasad\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/8084cf3db3cc9b2c21fc2c04307d47c7\"},\"headline\":\"Content Negotiation in Spring Framework\",\"datePublished\":\"2016-05-23T07:00:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.html\"},\"wordCount\":386,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.html\",\"name\":\"Content Negotiation in Spring Framework - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2016-05-23T07:00:05+00:00\",\"description\":\"1. Introduction With what we had done with\u00a0BeanNameViewResolver, is that we just had created multiple bean views in Spring context to generate the\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/05\\\/content-negotiation-spring-framework.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\\\/2016\\\/05\\\/content-negotiation-spring-framework.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\":\"Content Negotiation in Spring Framework\"}]},{\"@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\\\/8084cf3db3cc9b2c21fc2c04307d47c7\",\"name\":\"Abhimanyu Prasad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8197b6658b8d42a7c85117f4aabe67206651698dbc306809655610f6af906610?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8197b6658b8d42a7c85117f4aabe67206651698dbc306809655610f6af906610?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8197b6658b8d42a7c85117f4aabe67206651698dbc306809655610f6af906610?s=96&d=mm&r=g\",\"caption\":\"Abhimanyu Prasad\"},\"description\":\"Abhimanyu is a passionate tech blogger and senior programmer, who has an extensive end-to-end development experience with wide range of technologies. He is the founder and administrator at jCombat.\",\"sameAs\":[\"http:\\\/\\\/www.jcombat.com\",\"https:\\\/\\\/www.facebook.com\\\/abhi435\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/abhimanyu-prasad\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Content Negotiation in Spring Framework - Java Code Geeks","description":"1. Introduction With what we had done with\u00a0BeanNameViewResolver, is that we just had created multiple bean views in Spring context to generate the","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\/2016\/05\/content-negotiation-spring-framework.html","og_locale":"en_US","og_type":"article","og_title":"Content Negotiation in Spring Framework - Java Code Geeks","og_description":"1. Introduction With what we had done with\u00a0BeanNameViewResolver, is that we just had created multiple bean views in Spring context to generate the","og_url":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/abhi435","article_published_time":"2016-05-23T07:00:05+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":"Abhimanyu Prasad","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Abhimanyu Prasad","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html"},"author":{"name":"Abhimanyu Prasad","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/8084cf3db3cc9b2c21fc2c04307d47c7"},"headline":"Content Negotiation in Spring Framework","datePublished":"2016-05-23T07:00:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html"},"wordCount":386,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html","url":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html","name":"Content Negotiation in Spring Framework - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2016-05-23T07:00:05+00:00","description":"1. Introduction With what we had done with\u00a0BeanNameViewResolver, is that we just had created multiple bean views in Spring context to generate the","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2016\/05\/content-negotiation-spring-framework.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\/2016\/05\/content-negotiation-spring-framework.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":"Content Negotiation in Spring Framework"}]},{"@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\/8084cf3db3cc9b2c21fc2c04307d47c7","name":"Abhimanyu Prasad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/8197b6658b8d42a7c85117f4aabe67206651698dbc306809655610f6af906610?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8197b6658b8d42a7c85117f4aabe67206651698dbc306809655610f6af906610?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8197b6658b8d42a7c85117f4aabe67206651698dbc306809655610f6af906610?s=96&d=mm&r=g","caption":"Abhimanyu Prasad"},"description":"Abhimanyu is a passionate tech blogger and senior programmer, who has an extensive end-to-end development experience with wide range of technologies. He is the founder and administrator at jCombat.","sameAs":["http:\/\/www.jcombat.com","https:\/\/www.facebook.com\/abhi435"],"url":"https:\/\/www.javacodegeeks.com\/author\/abhimanyu-prasad"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/56504","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\/958"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=56504"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/56504\/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=56504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=56504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=56504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}