{"id":22737,"date":"2014-03-13T01:00:00","date_gmt":"2014-03-12T23:00:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=22737"},"modified":"2014-03-12T23:26:18","modified_gmt":"2014-03-12T21:26:18","slug":"creating-a-simple-jax-rs-messagebodywriter","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html","title":{"rendered":"Creating a simple JAX-RS MessageBodyWriter"},"content":{"rendered":"<p>JAX-RS is really cool and with the help of JAXB a lot of response data types can be converted for you simply by adding annotating the data objects with JAXB annotations. \u00a0I am fairly new at JAXB but some simple cut\/paste of annotations will take you a long way.<\/p>\n<p>There maybe some types of data that you can&#8217;t or won&#8217;t annotate for the purposes of returning that data type from a JAX-RS resource method. \u00a0 One simple example is returning either a boolean (primitive) or the wrapper Boolean class. \u00a0 I read a question on StackOverflow where someone asked if they could return a boolean from a resource method and since I didn&#8217;t know the answer, I decided to try it! \u00a0My version only returns XML, not JSON but you should get the idea.<\/p>\n<p>I started with the Jersey <a href=\"https:\/\/jersey.java.net\/documentation\/2.0\/getting-started.html#running-project\" target=\"_blank\">User&#8217;s Guide HelloWorld<\/a> example and starting modifying from there. \u00a0I used the pom.xml and the only change was to uncomment a block to allow using JSON.<\/p>\n<h2>Main class\u00a0<\/h2>\n<p>This the main class from the Hello World example without any changes.<\/p>\n<pre class=\" brush:java\">package com.example;\r\n\r\nimport org.glassfish.grizzly.http.server.HttpServer;\r\nimport org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;\r\nimport org.glassfish.jersey.server.ResourceConfig;\r\n\r\nimport java.io.IOException;\r\nimport java.net.URI;\r\n\r\n\/**\r\n * Main class.\r\n *\r\n *\/\r\npublic class Main {\r\n    \/\/ Base URI the Grizzly HTTP server will listen on\r\n    public static final String BASE_URI = \"http:\/\/localhost:8080\/myapp\/\";\r\n\r\n    \/**\r\n     * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.\r\n     * @return Grizzly HTTP server.\r\n     *\/\r\n    public static HttpServer startServer() {\r\n        \/\/ create a resource config that scans for JAX-RS resources and providers\r\n        \/\/ in com.example package\r\n        final ResourceConfig rc = new ResourceConfig().packages(\"com.example\");\r\n\r\n        \/\/ create and start a new instance of grizzly http server\r\n        \/\/ exposing the Jersey application at BASE_URI\r\n        return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);\r\n    }\r\n\r\n    \/**\r\n     * Main method.\r\n     * @param args\r\n     * @throws IOException\r\n     *\/\r\n    public static void main(String[] args) throws IOException {\r\n        final HttpServer server = startServer();\r\n        System.out.println(String.format(\"Jersey app started with WADL available at \"\r\n                + \"%sapplication.wadl\\nHit enter to stop it...\", BASE_URI));\r\n        System.in.read();\r\n        server.stop();\r\n    }\r\n}<\/pre>\n<h2>Resource class<\/h2>\n<p>I created a resource class that included a GET method to return a boolean and another GET method to return the wrapper Boolean class. \u00a0Notice the getBool() and getBoolean() methods return XML as the first option.<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 com.example;\r\n\r\nimport javax.ws.rs.GET;\r\nimport javax.ws.rs.Path;\r\nimport javax.ws.rs.Produces;\r\nimport javax.ws.rs.core.MediaType;\r\n\r\n\/**\r\n * Root resource (exposed at \"myresource\" path)\r\n *\/\r\n@Path(\"myresource\")\r\npublic class MyResource {\r\n\r\n    \/**\r\n     * Method handling HTTP GET requests. The returned object will be sent\r\n     * to the client as \"text\/plain\" media type.\r\n     *\r\n     * @return String that will be returned as a text\/plain response.\r\n     *\/\r\n    @GET\r\n    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})\r\n    public String getIt() {\r\n        return \"Got it!\";\r\n    }\r\n\r\n    @GET\r\n    @Path(\"\/bool\")\r\n    @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})\r\n    public boolean getBool() {\r\n        return false;\r\n    }\r\n\r\n    @GET\r\n    @Path(\"\/Boolean\")\r\n    @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})\r\n    public Boolean getBoolean() {\r\n        return Boolean.TRUE;\r\n    }\r\n}<\/pre>\n<h2>BooleanMessageBodyWriter class<\/h2>\n<p>Here&#8217;s the interesting part, creating the <a href=\"https:\/\/jsr311.java.net\/nonav\/javadoc\/javax\/ws\/rs\/ext\/MessageBodyWriter.html\" target=\"_blank\">MessageBodyWriter<\/a>\u00a0class to allow the resource method to return XML for the boolean or Boolean.<\/p>\n<pre class=\" brush:java\">package com.example;\r\n \r\nimport javax.ws.rs.Produces;\r\nimport javax.ws.rs.core.MediaType;\r\nimport javax.ws.rs.core.MultivaluedMap;\r\nimport javax.ws.rs.ext.MessageBodyWriter;\r\nimport javax.ws.rs.ext.Provider;\r\nimport javax.ws.rs.WebApplicationException;\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.io.DataOutputStream;\r\nimport java.io.ObjectOutputStream;\r\nimport java.io.OutputStream;\r\nimport java.io.PrintWriter;\r\nimport java.io.Serializable;\r\nimport java.lang.annotation.Annotation;\r\nimport java.lang.reflect.Type;\r\n \r\n@Provider\r\n@Produces(\"application\/xml\")\r\npublic class BooleanMessageBodyWriter implements MessageBodyWriter<boolean> {\r\n  \r\n    @Override\r\n    public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) {\r\n        System.out.println(\"isWriteable called...\");\r\n        return type == Boolean.class;\r\n    }\r\n  \r\n    @Override\r\n    public long getSize(Boolean myBool, Class type, Type genericType,\r\n                        Annotation[] annotations, MediaType mediaType) {\r\n        \/\/ deprecated by JAX-RS 2.0 and ignored by Jersey runtime\r\n        return 0;\r\n    }\r\n  \r\n    @Override\r\n    public void writeTo(Boolean myBool,\r\n                        Class type,\r\n                        Type genericType,\r\n                        Annotation[] annotations,\r\n                        MediaType mediaType,\r\n                        MultivaluedMap<string object=\"\"> httpHeaders,\r\n                        OutputStream entityStream)\r\n                        throws IOException, WebApplicationException {\r\n  \r\n        StringBuilder sb = new StringBuilder();\r\n        sb.append(\"<boolean><boolean>\").append(myBool.toString()).append(\"<\/boolean><\/boolean>\");\r\n        DataOutputStream dos = new DataOutputStream(entityStream);\r\n        dos.writeUTF(sb.toString());\r\n    }\r\n}\r\n<\/string><\/boolean><\/pre>\n<p>I \u00a0haven&#8217;t used Maven before but the following targets are all you need to compile and run the project, after installing maven (of course!).<\/p>\n<ul>\n<li><b>mvn compile<\/b> &#8211; compiles the code<\/li>\n<li><b>mvn exec:java<\/b> &#8211; starts the Grizzly HttpServer and deploys the restful service.<\/li>\n<\/ul>\n<p>Hope this helps!<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/programmingitch.blogspot.com\/2014\/03\/creating-simple-jax-rs-messagebodywriter.html\">Creating a simple JAX-RS MessageBodyWriter<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Mike Miller at the <a href=\"http:\/\/programmingitch.blogspot.com\/\">Scratching my programming itch<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>JAX-RS is really cool and with the help of JAXB a lot of response data types can be converted for you simply by adding annotating the data objects with JAXB annotations. \u00a0I am fairly new at JAXB but some simple cut\/paste of annotations will take you a long way. There maybe some types of data &hellip;<\/p>\n","protected":false},"author":434,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[439,54],"class_list":["post-22737","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-jax-rs","tag-restful-web-services"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Creating a simple JAX-RS MessageBodyWriter<\/title>\n<meta name=\"description\" content=\"JAX-RS is really cool and with the help of JAXB a lot of response data types can be converted for you simply by adding annotating the data objects with\" \/>\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\/03\/creating-a-simple-jax-rs-messagebodywriter.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating a simple JAX-RS MessageBodyWriter\" \/>\n<meta property=\"og:description\" content=\"JAX-RS is really cool and with the help of JAXB a lot of response data types can be converted for you simply by adding annotating the data objects with\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.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-03-12T23:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-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=\"Mike Miller\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/mikemil2713\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mike Miller\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html\"},\"author\":{\"name\":\"Mike Miller\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/d7933529fd39532e44652184e82db7c9\"},\"headline\":\"Creating a simple JAX-RS MessageBodyWriter\",\"datePublished\":\"2014-03-12T23:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html\"},\"wordCount\":317,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"JAX-RS\",\"RESTful Web Services\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html\",\"name\":\"Creating a simple JAX-RS MessageBodyWriter\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2014-03-12T23:00:00+00:00\",\"description\":\"JAX-RS is really cool and with the help of JAXB a lot of response data types can be converted for you simply by adding annotating the data objects with\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/03\\\/creating-a-simple-jax-rs-messagebodywriter.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\":\"Creating a simple JAX-RS MessageBodyWriter\"}]},{\"@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\\\/d7933529fd39532e44652184e82db7c9\",\"name\":\"Mike Miller\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a9710bbdabfaf8ecbd42a8accead0aa9390fe541635e4a6eac6c25d9cda58db8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a9710bbdabfaf8ecbd42a8accead0aa9390fe541635e4a6eac6c25d9cda58db8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a9710bbdabfaf8ecbd42a8accead0aa9390fe541635e4a6eac6c25d9cda58db8?s=96&d=mm&r=g\",\"caption\":\"Mike Miller\"},\"description\":\"Mike is a software developer who loves to learn how things work. A Java programmer who caught the Groovy &amp; Grails itch and is always looking for opportunities to include them as part of the solution.\",\"sameAs\":[\"http:\\\/\\\/programmingitch.blogspot.com\\\/\",\"http:\\\/\\\/www.linkedin.com\\\/pub\\\/mike-miller\\\/7\\\/78a\\\/496\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/mikemil2713\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/mike-miller\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Creating a simple JAX-RS MessageBodyWriter","description":"JAX-RS is really cool and with the help of JAXB a lot of response data types can be converted for you simply by adding annotating the data objects with","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\/03\/creating-a-simple-jax-rs-messagebodywriter.html","og_locale":"en_US","og_type":"article","og_title":"Creating a simple JAX-RS MessageBodyWriter","og_description":"JAX-RS is really cool and with the help of JAXB a lot of response data types can be converted for you simply by adding annotating the data objects with","og_url":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-03-12T23:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Mike Miller","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/mikemil2713","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mike Miller","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html"},"author":{"name":"Mike Miller","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/d7933529fd39532e44652184e82db7c9"},"headline":"Creating a simple JAX-RS MessageBodyWriter","datePublished":"2014-03-12T23:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html"},"wordCount":317,"commentCount":2,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["JAX-RS","RESTful Web Services"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html","url":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html","name":"Creating a simple JAX-RS MessageBodyWriter","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2014-03-12T23:00:00+00:00","description":"JAX-RS is really cool and with the help of JAXB a lot of response data types can be converted for you simply by adding annotating the data objects with","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/03\/creating-a-simple-jax-rs-messagebodywriter.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":"Creating a simple JAX-RS MessageBodyWriter"}]},{"@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\/d7933529fd39532e44652184e82db7c9","name":"Mike Miller","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a9710bbdabfaf8ecbd42a8accead0aa9390fe541635e4a6eac6c25d9cda58db8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a9710bbdabfaf8ecbd42a8accead0aa9390fe541635e4a6eac6c25d9cda58db8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a9710bbdabfaf8ecbd42a8accead0aa9390fe541635e4a6eac6c25d9cda58db8?s=96&d=mm&r=g","caption":"Mike Miller"},"description":"Mike is a software developer who loves to learn how things work. A Java programmer who caught the Groovy &amp; Grails itch and is always looking for opportunities to include them as part of the solution.","sameAs":["http:\/\/programmingitch.blogspot.com\/","http:\/\/www.linkedin.com\/pub\/mike-miller\/7\/78a\/496","https:\/\/x.com\/https:\/\/twitter.com\/mikemil2713"],"url":"https:\/\/www.javacodegeeks.com\/author\/mike-miller"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/22737","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\/434"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=22737"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/22737\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=22737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=22737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=22737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}