{"id":735,"date":"2011-12-23T16:21:00","date_gmt":"2011-12-23T16:21:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/develop-restful-web-services-using-spring-mvc.html"},"modified":"2012-10-21T20:48:09","modified_gmt":"2012-10-21T20:48:09","slug":"develop-restful-web-services-using","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html","title":{"rendered":"Develop Restful web services using Spring MVC"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\"><strong>REST INTRODUCTION<\/strong><\/p>\n<div style=\"text-align: justify\">\n<blockquote>\n<p>From Wikipedia:<strong> REST-style<\/strong> architectures consist of clients and servers. Clients initiate requests to servers; servers process requests and return appropriate responses. Requests and responses are built around the transfer of representations of resources. A resource can be essentially any coherent and meaningful concept that may be addressed.<\/p>\n<\/blockquote>\n<\/div>\n<div style=\"text-align: justify\">\nAs you have read the most important thing in <strong>Rest <\/strong>architecture is the existance of a resource. This resource &nbsp;can be anything (typically required information requested by client) that can be identified with a global identifier (<i>URI<\/i> in case of <i>HTTP<\/i>). In order to manipulate these resources, client communicates using standard interfaces (like <i>HTTP<\/i>) and exchange representations of these resources (using&nbsp;<i>HTML<\/i>, <i>XML<\/i>, &#8230;).<\/div>\n<div style=\"text-align: justify\">\n<\/div>\n<div style=\"text-align: justify\">Note that <strong>Rest<\/strong> does not force you to use any specific network protocol nor how resources are identified.<\/p>\n<p>For those who have never read about <strong>Rest<\/strong> this description of <strong>Rest<\/strong> architecture could seem something strange and bit complicated.&nbsp;<\/div>\n<div style=\"text-align: justify\">\n<\/div>\n<div style=\"text-align: justify\">A <strong>RESTful<\/strong> web service is a simple web service implemented using <i>HTTP<\/i> and the principles of <strong>REST<\/strong>. <i>URI<\/i> is defined as global identified, communication interface is HTTP and resource representation can be any valid Internet media type like <i>JSON<\/i>, <i>XML<\/i> or <i>YAML<\/i>. The set of operations that can be executed to resources depend on <i>HTTP<\/i> Methods and are (<i>GET<\/i> &#8211; retrieving\/listing, <i>PUT<\/i> &#8211; replacing\/updating, <i>POST<\/i> &#8211; creating and <i>DELETE<\/i> &#8211; deleting).<\/div>\n<div>\n<\/div>\n<div>\n<div><strong>HANDS ON WORK<\/strong><\/div>\n<div>\n<\/div>\n<div>\n<div style=\"text-align: justify\">Let&#8217;s create our first <strong>Rest<\/strong> application with help of <strong>Spring MVC<\/strong>. Imagine an application that has a database of manga characters, and you want to provide a <strong>Rest <\/strong>interface so clients can retrieve characters following a <strong>RESTful <\/strong>strategy.<\/div>\n<\/div>\n<div>\n<\/div>\n<div>\n<div style=\"text-align: justify\">First thing to do is identify the resource. In this case it is easy, &#8220;<i>a character<\/i>&#8220;. Next step is finding a <i>URI<\/i> that determines unequivocally a character. Easy too <i>de facto<\/i> rule can be applied here. This rule suggests that a unique <i>URI<\/i> can be &lt;host&gt;\/&lt;applicationname&gt;\/&lt;resourceName&gt;s\/&lt;id&gt; in our case to return (<i>GET<\/i>) character with id 1 the URI would be &#8220;<i>http:\/\/localhost:8080\/RestServer\/characters\/1<\/i>&#8220;. If no identifier is present all characters should be retrieved. If instead of <i>GET<\/i>, <i>POST<\/i> is used, a character with id &#8220;1&#8221; would be inserted. And finally decide which<i> Internet media type<\/i> is required, in this case doesn&#8217;t matter because we are implementing both client and server so initially <i>XML<\/i> will be used.<\/div>\n<\/div>\n<div>\n<\/div>\n<div style=\"text-align: justify\"><strong>CODING<\/strong><br \/>\nLet&#8217;s start with a simple <strong>Spring MVC<\/strong> application created with <strong>Spring MVC<\/strong> template. Not much secret here, you will have a <i>servlet-context.xml<\/i> where <i>component-scan<\/i>, <i>annotation-driven<\/i> and <i>InternalResourceViewResolver<\/i> are registered.<\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?&gt; \r\n&lt;beans:beans xmlns=\"http:\/\/www.springframework.org\/schema\/mvc\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:beans=\"http:\/\/www.springframework.org\/schema\/beans\" xmlns:context=\"http:\/\/www.springframework.org\/schema\/context\" xmlns:util=\"http:\/\/www.springframework.org\/schema\/util\" xsi:schemaLocation=\"http:\/\/www.springframework.org\/schema\/mvc http:\/\/www.springframework.org\/schema\/mvc\/spring-mvc-3.0.xsd http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.0.xsd http:\/\/www.springframework.org\/schema\/util http:\/\/www.springframework.org\/schema\/util\/spring-util-3.0.xsd http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.0.xsd\"&gt;\r\n &lt;!--  DispatcherServlet Context: defines this servlet's request-processing \r\n  infrastructure \r\n  --&gt; \r\n &lt;!--  Enables the Spring MVC @Controller programming model \r\n  --&gt; \r\n\r\n  &lt;annotation-driven \/&gt; \r\n\r\n &lt;!--  Resolves views selected for rendering by @Controllers to .jsp resources \r\n  in the \/WEB-INF\/views directory \r\n  --&gt; \r\n\r\n &lt;beans:bean class=\"org.springframework.web.servlet.view.InternalResourceViewResolver\"&gt;\r\n  &lt;beans:property name=\"prefix\" value=\"\/WEB-INF\/views\/\" \/&gt; \r\n  &lt;beans:property name=\"suffix\" value=\".jsp\" \/&gt; \r\n &lt;\/beans:bean&gt;\r\n\r\n  &lt;context:component-scan base-package=\"org.springframework.rest\" \/&gt; \r\n&lt;\/beans:beans&gt;\r\n<\/pre>\n<p>Next step is defining <i>Character<\/i> class. A simple <i>POJO <\/i>with four attributes. Class is converted to its <i>XML representation<\/i> using <i>Jaxb <\/i>annotation.  <i>Jaxb <\/i>allows developers to map <i>Java <\/i>classes to <i>XML <\/i>representations and viceversa.<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\">package org.springframework.rest;\r\n\r\nimport java.net.URL;\r\n\r\nimport org.codehaus.jackson.annotate.JsonAutoDetect;\r\n\r\n\r\n@XmlRootElement\r\npublic final class Character {\r\n\r\n private  int id;\r\n private  String name;\r\n private  boolean isHuman;\r\n private URL characterUrl;\r\n\r\n protected Character() {\r\n\r\n }\r\n\r\n public Character(int id, String name, boolean isHuman, URL characterUrl) {\r\n  super();\r\n  this.id = id;\r\n  this.name = name;\r\n  this.isHuman = isHuman;\r\n  this.characterUrl = characterUrl;\r\n }\r\n\r\n\r\n\r\n public int getId() {\r\n  return id;\r\n }\r\n\r\n public void setId(int id) {\r\n  this.id = id;\r\n }\r\n\r\n public String getName() {\r\n  return name;\r\n }\r\n\r\n public void setName(String name) {\r\n  this.name = name;\r\n }\r\n\r\n public boolean isHuman() {\r\n  return isHuman;\r\n }\r\n\r\n public void setHuman(boolean isHuman) {\r\n  this.isHuman = isHuman;\r\n }\r\n\r\n\r\n public URL getCharacterUrl() {\r\n  return characterUrl;\r\n }\r\n\r\n public void setCharacterUrl(URL characterUrl) {\r\n  this.characterUrl = characterUrl;\r\n }\r\n\r\n @Override\r\n public int hashCode() {\r\n  final int prime = 31;\r\n  int result = 1;\r\n  result = prime * result + id;\r\n  return result;\r\n }\r\n\r\n @Override\r\n public boolean equals(Object obj) {\r\n  if (this == obj)\r\n   return true;\r\n  if (obj == null)\r\n   return false;\r\n  if (getClass() != obj.getClass())\r\n   return false;\r\n  Character other = (Character) obj;\r\n  if (id != other.id)\r\n   return false;\r\n  return true;\r\n }\r\n\r\n\r\n}\r\n<\/pre>\n<p>And finally the most important class in <strong>Spring MVC<\/strong>, &#8220;<i>The Controller<\/i>&#8220;. Controller will be the responsible of implementing required operations of <i>Character <\/i>resource. In current case only <i>GET <\/i>is implemented, the other operations would be similar. Let&#8217;s see the code:<\/p>\n<pre class=\"brush:java\">@Controller\r\npublic class HomeController {\r\n\r\n\r\n private static final Map&lt;Integer, Character&gt; characters = new HashMap&lt;Integer, Character&gt;();\r\n\r\n static {\r\n  try {\r\n   characters.put(1, new Character(1, \"Totoro\", false, new URL(\"http:\/\/animeonly.org\/albums\/VISINAUJI\/EGIO\/fourth\/Mon-Voisin-Totoro\/normal_totoro_001.jpg\")));\r\n   characters.put(2, new Character(2, \"Satsuki Kusakabe\", true, new URL(\"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-ash2\/48980_1802552968_7286_n.jpg\")));\r\n   characters.put(3, new Character(3, \"Therru\", false, new URL(\"http:\/\/28.media.tumblr.com\/tumblr_lj4ctjKA8Y1qdvyqpo1_400.jpg\")));\r\n  } catch (MalformedURLException e) {\r\n   e.printStackTrace();\r\n  }\r\n }\r\n\r\n \/**\r\n  * Simply selects the home view to render by returning its name.\r\n  *\/\r\n @RequestMapping(value = \"\/characters\/{characterId}\", method = RequestMethod.GET)\r\n @ResponseBody\r\n public Character findCharacter(@PathVariable int characterId) {\r\n  return characters.get(characterId);\r\n\r\n\r\n }\r\n\r\n}\r\n<\/pre>\n<p>First part is a map where all characters are stored. I have used this approach to not focus in data access. Then <i>findCharacter <\/i>method that is called when <i>URI <\/i>is <i>\/characters\/{characterId<\/i>}. This is a <i>URI <\/i>template and is a <i>URI<\/i>-like string, containing one or more variable names, which can be accessed using <i>@PathVariable<\/i> annotation. So when you are accessing to <i>\/characters\/1<\/i> parameter <i>characterId<\/i> is bound to 1.<\/p>\n<p>Last important part is<i> @ResponseBody <\/i>annotation. This annotation can be put on a method and indicates that the return type should be written straight to the <i>HTTP <\/i>response body, and not placed in a <i>Model<\/i>, or interpreted as a view name as standard behaviour of <strong>Spring MVC<\/strong>. So <i>findCharacter <\/i>method returns a <i>Character <\/i>object.<\/p>\n<p>And that&#8217;s all if you execute this code, and for example you enter <i>URI http:\/\/localhost:8080\/RestServer\/characters\/1<\/i> the output (using <a href=\"http:\/\/code.google.com\/p\/rest-client\/\">RestClient UI<\/a>) will be:<\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/4.bp.blogspot.com\/-DoKM4KSBsmg\/ToSkzHzekAI\/AAAAAAAAGAM\/HOThgEYoUuc\/s640\/restXML.JPG\"><img decoding=\"async\" border=\"0\" height=\"324\" src=\"http:\/\/4.bp.blogspot.com\/-DoKM4KSBsmg\/ToSkzHzekAI\/AAAAAAAAGAM\/HOThgEYoUuc\/s640\/restXML.JPG\" width=\"640\" \/><\/a><\/div>\n<p>And now is when you are wondering, \u00bfIf I am returning a <i>Character <\/i>object and output is a <i>XML<\/i>, where is conversion between object and <i>XML<\/i>? So easy, let me introduce a new concept: <strong>HttpMessageConverters<\/strong>. <strong>HttpMessageConverter <\/strong>is responsible for converting from <i>HTTP<\/i> request message to an object and converting from an object to <i>HTTP <\/i>response body. Next <strong>HttpMessageConverters <\/strong>are registered by default:<\/div>\n<\/div>\n<div style=\"text-align: justify\">\n<\/div>\n<div style=\"text-align: justify\">\n<div style=\"text-align: justify\"><i><span class=\"Apple-tab-span\"> <\/span>&#8211; ByteArrayHttpMessageConverter<\/i><\/div>\n<div style=\"text-align: justify\"><i><span class=\"Apple-tab-span\"> <\/span>&#8211; StringHttpMessageConverter<\/i><\/div>\n<div style=\"text-align: justify\"><i><span class=\"Apple-tab-span\"> <\/span>&#8211; ResourceHttpMessageConverter<\/i><\/div>\n<div style=\"text-align: justify\"><i><span class=\"Apple-tab-span\"> <\/span>&#8211; SourceHttpMessageConverter<\/i><\/div>\n<div style=\"text-align: justify\"><i><span class=\"Apple-tab-span\"> <\/span>&#8211; XmlAwareHttpMessageConverter<\/i><\/div>\n<div style=\"text-align: justify\"><i><span class=\"Apple-tab-span\"> <\/span>&#8211; Jaxb2RootElementHttpMessageConverter<\/i><\/div>\n<div style=\"text-align: justify\"><i><span class=\"Apple-tab-span\"> <\/span>&#8211; MappingJacksonHttpMessageConverter<\/i><\/div>\n<div style=\"text-align: justify\">\n<\/div>\n<div style=\"text-align: justify\">\n<div style=\"text-align: justify\">So now you understand why works perfectly. When you are returning <i>Character <\/i>instance, <strong>Jaxb2RootElementHttpMessageConverter <\/strong>using <i>canWrite <\/i>method checks if class contains <i>XmlRootElement <\/i>annotation. If class is annotated, write method is called. In this case <i>Jaxb <\/i>marshaller is called, and <i>XML <\/i>is returned. Same from <i>XML <\/i>to object but using <i>Jaxb <\/i>unmarshaller class.<\/div>\n<div style=\"text-align: justify\">\n<\/div>\n<div style=\"text-align: justify\">So easy, no complicated configurations, no complicated mappings, no unclear code, and you only need to worry about your model objects, not in conversion. But let me introduce one change. Now instead of returning <i>XML <\/i>we want to return <i>JSON<\/i>.<\/div>\n<div style=\"text-align: justify\">\n<\/div>\n<div style=\"text-align: justify\">Change could not be easier, add <i>Jackson<\/i> library to <i>pom.xml<\/i> and change <i>@XmlRootElement<\/i> to <i>@JsonAutoDetect<\/i>. And now <strong>MappingJacksonHttpMessageConverter <\/strong>will handle this object and will transform <i>Character <\/i>instance to <i>JSON <\/i>protocol using <i>Jackson<\/i> library. Only changing one line of code!!!<\/div>\n<div style=\"text-align: justify\">\n<\/div>\n<div style=\"text-align: justify\">And now output will be:<\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/2.bp.blogspot.com\/--9RWRSNSVzI\/ToSk-WnAQuI\/AAAAAAAAGAQ\/Ho7R-GCDrfw\/s640\/restJSON.JPG\"><img decoding=\"async\" border=\"0\" height=\"396\" src=\"http:\/\/2.bp.blogspot.com\/--9RWRSNSVzI\/ToSk-WnAQuI\/AAAAAAAAGAQ\/Ho7R-GCDrfw\/s640\/restJSON.JPG\" width=\"640\" \/><\/a><\/div>\n<p><strong>CONCLUSIONS<\/strong><\/p>\n<p>Of course this is a very simple application with only one operation, but it gives you an idea of how to develop <strong>Restful <\/strong>web services using <strong>Spring MVC<\/strong>. It is a matter of time of writing all your required operations using same approach that I have used with <strong>GET<\/strong>.<\/p>\n<p>Arriving at this point I think that all of us have arrived to same conclusion. Annotations are really really powerful, and <strong>Spring MVC<\/strong> fits perfectly for developing <strong>RESTful<\/strong> <strong>web<\/strong> services.<\/p>\n<p>See you next time&#8230;<\/p>\n<p><a href=\"https:\/\/github.com\/downloads\/maggandalf\/Blog-Examples\/restserver.zip\">Download Code.<\/a><\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/www.lordofthejars.com\/2011\/10\/cant-you-see-it-all-makes-perfect-sense.html\">Develop Restful web services using Spring MVC<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a>&nbsp;Alex Soto at the&nbsp;<a href=\"http:\/\/www.lordofthejars.com\/\">One Jar To Rule Them All<\/a> blog.<\/p>\n<p><strong><i>Related Articles :<\/i><\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/jqgrid-rest-ajax-spring-mvc-integration.html\">jqGrid, REST, AJAX and Spring MVC Integration<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/10\/java-restful-api-integration-testing.html\">Java RESTful API integration testing<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/building-restful-web-service-with.html\">Building a RESTful Web Service with Spring 3.1 and Java based Configuration, part 2<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/05\/android-json-gson-revisited.html\">Android JSON Parsing with Gson Revisited<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/01\/restful-web-services-with-resteasy-jax.html\">RESTful Web Services with RESTeasy JAX-RS on Tomcat 7 \u2013 Eclipse and Maven project<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/06\/spring-3-restful-web-services.html\">Spring 3 RESTful Web Services<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/02\/spring-mvc-development-tutorial.html\">Spring MVC Development &#8211; Quick Tutorial<\/a><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>REST INTRODUCTION From Wikipedia: REST-style architectures consist of clients and servers. Clients initiate requests to servers; servers process requests and return appropriate responses. Requests and responses are built around the transfer of representations of resources. A resource can be essentially any coherent and meaningful concept that may be addressed. As you have read the most &hellip;<\/p>\n","protected":false},"author":119,"featured_media":175,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[162,144,69,54,150,107],"class_list":["post-735","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-jackson","tag-jaxb","tag-json","tag-restful-web-services","tag-spring-mvc","tag-xml"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Develop Restful web services using Spring MVC - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"REST INTRODUCTION From Wikipedia: REST-style architectures consist of clients and servers. Clients initiate requests to servers; servers process requests\" \/>\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\/2011\/12\/develop-restful-web-services-using.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Develop Restful web services using Spring MVC - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"REST INTRODUCTION From Wikipedia: REST-style architectures consist of clients and servers. Clients initiate requests to servers; servers process requests\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.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=\"2011-12-23T16:21:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T20:48:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-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=\"Alex Soto\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@http:\/\/twitter.com\/alexsotob\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alex Soto\" \/>\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\\\/2011\\\/12\\\/develop-restful-web-services-using.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.html\"},\"author\":{\"name\":\"Alex Soto\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/6566a1238c71f5d85ba5b5df5d2eac59\"},\"headline\":\"Develop Restful web services using Spring MVC\",\"datePublished\":\"2011-12-23T16:21:00+00:00\",\"dateModified\":\"2012-10-21T20:48:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.html\"},\"wordCount\":1037,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"keywords\":[\"Jackson\",\"JAXB\",\"JSON\",\"RESTful Web Services\",\"Spring MVC\",\"XML\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.html\",\"name\":\"Develop Restful web services using Spring MVC - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"datePublished\":\"2011-12-23T16:21:00+00:00\",\"dateModified\":\"2012-10-21T20:48:09+00:00\",\"description\":\"REST INTRODUCTION From Wikipedia: REST-style architectures consist of clients and servers. Clients initiate requests to servers; servers process requests\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/12\\\/develop-restful-web-services-using.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\":\"Develop Restful web services using Spring MVC\"}]},{\"@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\\\/6566a1238c71f5d85ba5b5df5d2eac59\",\"name\":\"Alex Soto\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cc3a211b790033d32fee33bb321b7bb6e2d381dab14531d3f2e8df9885bca7f9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cc3a211b790033d32fee33bb321b7bb6e2d381dab14531d3f2e8df9885bca7f9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cc3a211b790033d32fee33bb321b7bb6e2d381dab14531d3f2e8df9885bca7f9?s=96&d=mm&r=g\",\"caption\":\"Alex Soto\"},\"sameAs\":[\"http:\\\/\\\/www.lordofthejars.com\\\/\",\"https:\\\/\\\/x.com\\\/http:\\\/\\\/twitter.com\\\/alexsotob\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Alex-Soto\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Develop Restful web services using Spring MVC - Java Code Geeks","description":"REST INTRODUCTION From Wikipedia: REST-style architectures consist of clients and servers. Clients initiate requests to servers; servers process requests","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\/2011\/12\/develop-restful-web-services-using.html","og_locale":"en_US","og_type":"article","og_title":"Develop Restful web services using Spring MVC - Java Code Geeks","og_description":"REST INTRODUCTION From Wikipedia: REST-style architectures consist of clients and servers. Clients initiate requests to servers; servers process requests","og_url":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-12-23T16:21:00+00:00","article_modified_time":"2012-10-21T20:48:09+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","type":"image\/jpeg"}],"author":"Alex Soto","twitter_card":"summary_large_image","twitter_creator":"@http:\/\/twitter.com\/alexsotob","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Alex Soto","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html"},"author":{"name":"Alex Soto","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/6566a1238c71f5d85ba5b5df5d2eac59"},"headline":"Develop Restful web services using Spring MVC","datePublished":"2011-12-23T16:21:00+00:00","dateModified":"2012-10-21T20:48:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html"},"wordCount":1037,"commentCount":6,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","keywords":["Jackson","JAXB","JSON","RESTful Web Services","Spring MVC","XML"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html","url":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html","name":"Develop Restful web services using Spring MVC - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","datePublished":"2011-12-23T16:21:00+00:00","dateModified":"2012-10-21T20:48:09+00:00","description":"REST INTRODUCTION From Wikipedia: REST-style architectures consist of clients and servers. Clients initiate requests to servers; servers process requests","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2011\/12\/develop-restful-web-services-using.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":"Develop Restful web services using Spring MVC"}]},{"@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\/6566a1238c71f5d85ba5b5df5d2eac59","name":"Alex Soto","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cc3a211b790033d32fee33bb321b7bb6e2d381dab14531d3f2e8df9885bca7f9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cc3a211b790033d32fee33bb321b7bb6e2d381dab14531d3f2e8df9885bca7f9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cc3a211b790033d32fee33bb321b7bb6e2d381dab14531d3f2e8df9885bca7f9?s=96&d=mm&r=g","caption":"Alex Soto"},"sameAs":["http:\/\/www.lordofthejars.com\/","https:\/\/x.com\/http:\/\/twitter.com\/alexsotob"],"url":"https:\/\/www.javacodegeeks.com\/author\/Alex-Soto"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/735","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\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=735"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/735\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/175"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}