{"id":12332,"date":"2013-05-07T01:00:45","date_gmt":"2013-05-06T22:00:45","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=12332"},"modified":"2013-05-06T09:58:37","modified_gmt":"2013-05-06T06:58:37","slug":"using-java-websockets-jsr-356-and-json-mapped-to-pojos","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html","title":{"rendered":"Using Java WebSockets, JSR 356, and JSON mapped to POJO&#8217;s"},"content":{"rendered":"<p>So I have been playing around with <a href=\"http:\/\/tyrus.java.net\">Tyrus<\/a>, the reference implementation of the JSR 356 WebSocket for Java spec. Because I was looking at test tooling I was interested in running both the client and the server side in Java. So no HTML5 in this blog post I am afraid.<\/p>\n<p>In this example we want to sent JSON back and forth and because I am old fashioned like that I want to be able to bind to a POJO object. I am going to use Jackson for this so my maven file looks like this:<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<pre class=\" brush:xml\">&lt;dependencies&gt;\r\n    &lt;dependency&gt;\r\n        &lt;groupId&gt;javax.websocket&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;javax.websocket-api&lt;\/artifactId&gt;\r\n        &lt;version&gt;1.0-rc3&lt;\/version&gt;\r\n    &lt;\/dependency&gt;\r\n\r\n    &lt;dependency&gt;\r\n        &lt;groupId&gt;org.glassfish.tyrus&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;tyrus-client&lt;\/artifactId&gt;\r\n        &lt;version&gt;1.0-rc3&lt;\/version&gt;\r\n    &lt;\/dependency&gt;\r\n\r\n    &lt;dependency&gt;\r\n        &lt;groupId&gt;org.glassfish.tyrus&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;tyrus-server&lt;\/artifactId&gt;\r\n        &lt;version&gt;1.0-rc3&lt;\/version&gt;\r\n    &lt;\/dependency&gt;\r\n\r\n    &lt;dependency&gt;\r\n        &lt;groupId&gt;org.glassfish.tyrus&lt;\/groupId&gt;\r\n        &lt;artifactId&gt;tyrus-container-grizzly&lt;\/artifactId&gt;\r\n        &lt;version&gt;1.0-rc3&lt;\/version&gt;\r\n    &lt;\/dependency&gt;\r\n\r\n    &lt;dependency&gt;\r\n      &lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;\r\n      &lt;artifactId&gt;jackson-databind&lt;\/artifactId&gt;\r\n      &lt;version&gt;2.2.0&lt;\/version&gt;\r\n    &lt;\/dependency&gt;\r\n\r\n    &lt;dependency&gt;\r\n      &lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;\r\n      &lt;artifactId&gt;jackson-annotations&lt;\/artifactId&gt;\r\n      &lt;version&gt;2.2.0&lt;\/version&gt;\r\n    &lt;\/dependency&gt;\r\n\r\n    &lt;dependency&gt;\r\n      &lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;\r\n      &lt;artifactId&gt;jackson-core&lt;\/artifactId&gt;\r\n      &lt;version&gt;2.2.0&lt;\/version&gt;\r\n    &lt;\/dependency&gt;\r\n\r\n  &lt;\/dependencies&gt;<\/pre>\n<p>So the first things we need to do is to define an implementations of the Encode\/Decoder interfaces to do this work for us. This is going to do some simple reflection to workout what the bean class is. Like with JAX-WS it is easier to put them on the same class. Note that we use the streaming version of the interface and are only handling text content. (Ignoring the ability to send binary data for the moment)<\/p>\n<pre class=\" brush:java\">package websocket;\r\n\r\nimport com.fasterxml.jackson.databind.ObjectMapper;\r\n\r\nimport java.io.IOException;\r\nimport java.io.Reader;\r\nimport java.io.Writer;\r\n\r\nimport java.lang.reflect.ParameterizedType;\r\nimport java.lang.reflect.Type;\r\n\r\nimport javax.websocket.DecodeException;\r\nimport javax.websocket.Decoder;\r\nimport javax.websocket.EncodeException;\r\nimport javax.websocket.Encoder;\r\nimport javax.websocket.EndpointConfig;\r\n\r\npublic abstract class JSONCoder&lt;T&gt;\r\n  implements Encoder.TextStream&lt;T&gt;, Decoder.TextStream&lt;T&gt;{\r\n\r\n    private Class&lt;T&gt; _type;\r\n\r\n    \/\/ When configured my read in that ObjectMapper is not thread safe\r\n    \/\/\r\n    private ThreadLocal&lt;ObjectMapper&gt; _mapper = new ThreadLocal&lt;ObjectMapper&gt;() {\r\n\r\n        @Override\r\n        protected ObjectMapper initialValue() {\r\n            return new ObjectMapper();\r\n        }\r\n    };\r\n\r\n    @Override\r\n    public void init(EndpointConfig endpointConfig) {\r\n\r\n        ParameterizedType $thisClass = (ParameterizedType) this.getClass().getGenericSuperclass();\r\n        Type $T = $thisClass.getActualTypeArguments()[0];\r\n        if ($T instanceof Class) {\r\n            _type = (Class&lt;T&gt;)$T;\r\n        }\r\n        else if ($T instanceof ParameterizedType) {\r\n            _type = (Class&lt;T&gt;)((ParameterizedType)$T).getRawType();\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public void encode(T object, Writer writer) throws EncodeException, IOException {\r\n        _mapper.get().writeValue(writer, object);\r\n    }\r\n\r\n    @Override\r\n    public T decode(Reader reader) throws DecodeException, IOException {\r\n        return _mapper.get().readValue(reader, _type);\r\n    }\r\n\r\n    @Override\r\n    public void destroy() {\r\n\r\n    }\r\n\r\n}<\/pre>\n<p>The bean class is really quite simple with a static subclass of the Coder that we can use later.<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 websocket;\r\n\r\npublic class EchoBean {\r\n\r\n    public static class EchoBeanCode extends\r\n       JSONCoder&lt;EchoBean&gt; {\r\n\r\n    }\r\n\r\n    private String _message;\r\n    private String _reply;\r\n\r\n    public EchoBean() {\r\n\r\n    }\r\n\r\n    public EchoBean(String _message) {\r\n        super();\r\n        this._message = _message;\r\n    }\r\n\r\n    public void setMessage(String _message) {\r\n        this._message = _message;\r\n    }\r\n\r\n    public String getMessage() {\r\n        return _message;\r\n    }\r\n\r\n    public void setReply(String _reply) {\r\n        this._reply = _reply;\r\n    }\r\n\r\n    public String getReply() {\r\n        return _reply;\r\n    }\r\n\r\n}<\/pre>\n<p>So new we need to implement our server endpoint, you can go one of two way either annotating a POJO or extending Endpoint. I am going with the first for the server and the second for the client. Really all this service does is to post the message back to the client. Note the registration of the encode and decoder. The same class in this case.<\/p>\n<pre class=\" brush:java\">package websocket;\r\n\r\nimport java.io.IOException;\r\n\r\nimport javax.websocket.EncodeException;\r\nimport javax.websocket.EndpointConfig;\r\nimport javax.websocket.OnMessage;\r\nimport javax.websocket.OnOpen;\r\nimport javax.websocket.Session;\r\nimport javax.websocket.server.ServerEndpoint;\r\nimport static java.lang.System.out;\r\n\r\n@ServerEndpoint(value=\"\/echo\",\r\n                encoders = {EchoBean.EchoBeanCode.class},\r\n                decoders = {EchoBean.EchoBeanCode.class})\r\npublic class EchoBeanService\r\n{\r\n\r\n    @OnMessage\r\n    public void echo (EchoBean bean, Session peer) throws IOException, EncodeException {\r\n        \/\/\r\n        bean.setReply(\"Server says \" + bean.getMessage());\r\n        out.println(\"Sending message to client\");\r\n        peer.getBasicRemote().sendObject(bean);\r\n    }\r\n\r\n    @OnOpen\r\n    public void onOpen(final Session session, EndpointConfig endpointConfig) {\r\n        out.println(\"Server connected \"  + session + \" \" + endpointConfig);\r\n    }\r\n}<\/pre>\n<p>Lets look at a client bean, this time extending the standard Endpoint class and adding a specific listener for a message. In this case when the message is received the connection is simply closed to make our test case simple. In the real world managing this connection would obviously be more complicated.<\/p>\n<pre class=\" brush:java\">package websocket;\r\n\r\nimport java.io.IOException;\r\n\r\nimport javax.websocket.ClientEndpoint;\r\nimport javax.websocket.CloseReason;\r\nimport javax.websocket.EncodeException;\r\nimport javax.websocket.Endpoint;\r\nimport javax.websocket.EndpointConfig;\r\nimport javax.websocket.MessageHandler;\r\nimport javax.websocket.Session;\r\n\r\nimport static java.lang.System.out;\r\n\r\n@ClientEndpoint(encoders = {EchoBean.EchoBeanCode.class},\r\n                decoders = {EchoBean.EchoBeanCode.class})\r\npublic class EchoBeanClient \r\n  extends Endpoint\r\n{\r\n    public void onOpen(final Session session, EndpointConfig endpointConfig) {\r\n\r\n        out.println(\"Client Connection open \"  + session + \" \" + endpointConfig);\r\n\r\n        \/\/ Add a listener to capture the returning event\r\n        \/\/\r\n\r\n        session.addMessageHandler(new MessageHandler.Whole() {\r\n\r\n            @Override\r\n            public void onMessage(EchoBean bean) {\r\n                out.println(\"Message from server : \" + bean.getReply());\r\n\r\n                out.println(\"Closing connection\");\r\n                try {\r\n                    session.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, \"All fine\"));\r\n                } catch (IOException e) {\r\n                    e.printStackTrace();\r\n                }\r\n            }\r\n        });\r\n\r\n        \/\/ Once we are connected we can now safely send out initial message to the server\r\n        \/\/\r\n\r\n        out.println(\"Sending message to server\");\r\n        try {\r\n            EchoBean bean = new EchoBean(\"Hello\");\r\n            session.getBasicRemote().sendObject(bean);\r\n        } catch (IOException e) {\r\n            e.printStackTrace();\r\n        } catch (EncodeException e) {\r\n            e.printStackTrace();\r\n        }\r\n\r\n    }\r\n}<\/pre>\n<p>Now running the WebSocket standalone is really quite straightforward with Tyrus, you simple instantiate a Server and start it. Be aware this starts daemon threads so you need to make sure if this is in a main method that you do something to keep the JVM alive.<\/p>\n<pre class=\" brush:java\">import org.glassfish.tyrus.server.Server;\r\n\r\nServer server = new Server(\"localhost\", 8025, \"\/\", EchoBeanService.class);\r\nserver.start();<\/pre>\n<p>So the client is relatively simple; but as we are doing the declarative method we need to explicitly register the encoders and decoders when registering the client class.<\/p>\n<pre class=\" brush:java\">import javax.websocket.ClientEndpointConfig;\r\nimport javax.websocket.Decoder;\r\nimport javax.websocket.Encoder;\r\nimport javax.websocket.Session;\r\n\r\nimport org.glassfish.tyrus.client.ClientManager;\r\n\r\n\/\/ Right now we have to create a client, which will send a message then close\r\n\/\/ when it has received a reply\r\n\/\/\r\n\r\nClientManager client = ClientManager.createClient();\r\nEchoBeanClient beanClient = new EchoBeanClient();\r\n\r\nSession session = client.connectToServer(\r\n        beanClient, \r\n        ClientEndpointConfig.Builder.create()\r\n         .encoders(Arrays.&lt;Class&lt;? extends Encoder&gt;&gt;asList(EchoBean.EchoBeanCode.class))\r\n         .decoders(Arrays.&lt;Class&lt;? extends Decoder&gt;&gt;asList(EchoBean.EchoBeanCode.class))\r\n         .build(),\r\n        URI.create(\"ws:\/\/localhost:8025\/echo\"));\r\n\r\n\/\/ Wait until things are closed down\r\n\r\nwhile (session.isOpen()) {\r\n    out.println(\"Waiting\");\r\n    TimeUnit.MILLISECONDS.sleep(10);\r\n}<\/pre>\n<p>Now the output of this looks like the following:<\/p>\n<pre class=\" brush:java\">Server connected SessionImpl{uri=\/echo, id='e7739cc8-1ce5-4c26-ad5f-88a24c688799', endpoint=EndpointWrapper{endpointClass=null, endpoint=org.glassfish.tyrus.core.AnnotatedEndpoint@1ce5bc9, uri='\/echo', contextPath='\/'}} javax.websocket.server.DefaultServerEndpointConfig@ec120d\r\nWaiting\r\nClient Connection open SessionImpl{uri=ws:\/\/localhost:8025\/echo, id='7428be2b-6f8a-4c40-a0c4-b1c8b22e1338', endpoint=EndpointWrapper{endpointClass=null, endpoint=websocket.EchoBeanClient@404c85, uri='ws:\/\/localhost:8025\/echo', contextPath='ws:\/\/localhost:8025\/echo'}} javax.websocket.DefaultClientEndpointConfig@15fdf14\r\nSending message to server\r\nWaiting\r\nWaiting\r\nWaiting\r\nWaiting\r\nWaiting\r\nWaiting\r\nWaiting\r\nWaiting\r\nWaiting\r\nWaiting\r\nSending message to client\r\nMessage from server : Server says Hello\r\nClosing connection\r\nWaiting<\/pre>\n<p>Interestingly the first time this is run the there is a pause, I suspect this is due to Jackson setting itself up but I haven&#8217;t had time to profile. I did find that this long delay on occurred on the first post &#8211; although obviously this is going to be slower than just passing plain text messages in general. Whether the different is significant to you depends on your application.<\/p>\n<p>It would be interesting to compare the performance of the plain text with a JSON stream API such as that provided by the new JSR and of course the version that binds those values to a JSON POJO. Something for another day perhaps.<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:\/\/kingsfleet.blogspot.com\/2013\/04\/using-java-websockets-jsr-356-and-json.html\">Using Java WebSockets, JSR 356, and JSON mapped to POJO&#8217;s<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Gerard Davison at the <a href=\"http:\/\/kingsfleet.blogspot.com\/\">Gerard Davison&#8217;s blog<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>So I have been playing around with Tyrus, the reference implementation of the JSR 356 WebSocket for Java spec. Because I was looking at test tooling I was interested in running both the client and the server side in Java. So no HTML5 in this blog post I am afraid. In this example we want &hellip;<\/p>\n","protected":false},"author":81,"featured_media":175,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[69,776,399],"class_list":["post-12332","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-json","tag-jsr-356","tag-websockets"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using Java WebSockets, JSR 356, and JSON mapped to POJO&#039;s<\/title>\n<meta name=\"description\" content=\"So I have been playing around with Tyrus, the reference implementation of the JSR 356 WebSocket for Java spec. Because I was looking at test tooling I was\" \/>\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\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Java WebSockets, JSR 356, and JSON mapped to POJO&#039;s\" \/>\n<meta property=\"og:description\" content=\"So I have been playing around with Tyrus, the reference implementation of the JSR 356 WebSocket for Java spec. Because I was looking at test tooling I was\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.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=\"2013-05-06T22:00:45+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=\"Gerard Davison\" \/>\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=\"Gerard Davison\" \/>\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\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html\"},\"author\":{\"name\":\"Gerard Davison\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cce8956b05b5728c0fd17b376131759b\"},\"headline\":\"Using Java WebSockets, JSR 356, and JSON mapped to POJO&#8217;s\",\"datePublished\":\"2013-05-06T22:00:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html\"},\"wordCount\":545,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"keywords\":[\"JSON\",\"JSR 356\",\"WebSockets\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html\",\"name\":\"Using Java WebSockets, JSR 356, and JSON mapped to POJO's\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/json-logo.jpg\",\"datePublished\":\"2013-05-06T22:00:45+00:00\",\"description\":\"So I have been playing around with Tyrus, the reference implementation of the JSR 356 WebSocket for Java spec. Because I was looking at test tooling I was\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.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\\\/2013\\\/05\\\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.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\":\"Using Java WebSockets, JSR 356, and JSON mapped to POJO&#8217;s\"}]},{\"@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\\\/cce8956b05b5728c0fd17b376131759b\",\"name\":\"Gerard Davison\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3328b0eb2ba0cbf63dde5eca8855fae1bb66ddf6a8ea42967f984151c1c7a9f0?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3328b0eb2ba0cbf63dde5eca8855fae1bb66ddf6a8ea42967f984151c1c7a9f0?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3328b0eb2ba0cbf63dde5eca8855fae1bb66ddf6a8ea42967f984151c1c7a9f0?s=96&d=mm&r=g\",\"caption\":\"Gerard Davison\"},\"sameAs\":[\"http:\\\/\\\/kingsfleet.blogspot.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Gerard-Davison\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using Java WebSockets, JSR 356, and JSON mapped to POJO's","description":"So I have been playing around with Tyrus, the reference implementation of the JSR 356 WebSocket for Java spec. Because I was looking at test tooling I was","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\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html","og_locale":"en_US","og_type":"article","og_title":"Using Java WebSockets, JSR 356, and JSON mapped to POJO's","og_description":"So I have been playing around with Tyrus, the reference implementation of the JSR 356 WebSocket for Java spec. Because I was looking at test tooling I was","og_url":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-05-06T22:00:45+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":"Gerard Davison","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Gerard Davison","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html"},"author":{"name":"Gerard Davison","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cce8956b05b5728c0fd17b376131759b"},"headline":"Using Java WebSockets, JSR 356, and JSON mapped to POJO&#8217;s","datePublished":"2013-05-06T22:00:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html"},"wordCount":545,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","keywords":["JSON","JSR 356","WebSockets"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html","url":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html","name":"Using Java WebSockets, JSR 356, and JSON mapped to POJO's","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/json-logo.jpg","datePublished":"2013-05-06T22:00:45+00:00","description":"So I have been playing around with Tyrus, the reference implementation of the JSR 356 WebSocket for Java spec. Because I was looking at test tooling I was","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.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\/2013\/05\/using-java-websockets-jsr-356-and-json-mapped-to-pojos.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":"Using Java WebSockets, JSR 356, and JSON mapped to POJO&#8217;s"}]},{"@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\/cce8956b05b5728c0fd17b376131759b","name":"Gerard Davison","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3328b0eb2ba0cbf63dde5eca8855fae1bb66ddf6a8ea42967f984151c1c7a9f0?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3328b0eb2ba0cbf63dde5eca8855fae1bb66ddf6a8ea42967f984151c1c7a9f0?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3328b0eb2ba0cbf63dde5eca8855fae1bb66ddf6a8ea42967f984151c1c7a9f0?s=96&d=mm&r=g","caption":"Gerard Davison"},"sameAs":["http:\/\/kingsfleet.blogspot.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Gerard-Davison"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/12332","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\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=12332"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/12332\/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=12332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=12332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=12332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}