Bael 389 - Chat-like app using the Java API for WebSocket (#1265)

* Project for " A Guide to the Java API for WebSocket" article

* Setting dependencies correctly

* Formatting adjustments

* Removing tomcat7 maven plugin

* Applying formatt - No spaces
This commit is contained in:
Alex Vargas
2017-03-05 02:09:37 -08:00
committed by Zeger Hendrikse
parent 181688a765
commit c83c449fa5
10 changed files with 408 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package com.baeldung.websocket;
import javax.websocket.DecodeException;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;
import com.baeldung.model.Message;
import com.google.gson.Gson;
public class MessageDecoder implements Decoder.Text<Message> {
@Override
public Message decode(String s) throws DecodeException {
Gson gson = new Gson();
Message message = gson.fromJson(s, Message.class);
return message;
}
@Override
public boolean willDecode(String s) {
return (s != null);
}
@Override
public void init(EndpointConfig endpointConfig) {
// Custom initialization logic
}
@Override
public void destroy() {
// Close resources
}
}