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:
committed by
Zeger Hendrikse
parent
181688a765
commit
c83c449fa5
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.websocket;
|
||||
|
||||
import javax.websocket.EncodeException;
|
||||
import javax.websocket.Encoder;
|
||||
import javax.websocket.EndpointConfig;
|
||||
|
||||
import com.baeldung.model.Message;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class MessageEncoder implements Encoder.Text<Message> {
|
||||
@Override
|
||||
public String encode(Message message) throws EncodeException {
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(message);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(EndpointConfig endpointConfig) {
|
||||
// Custom initialization logic
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Close resources
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user