Alex Vargas 84c71b3dbf Bael 389 - Making Gson field in both classes static (#1366)
* Project for " A Guide to the Java API for WebSocket" article

* Setting dependencies correctly

* Formatting adjustments

* Removing tomcat7 maven plugin

* Applying formatt - No spaces

* BAEL-389 - Building URL dynamically between host and pathname

* Setting javax websocket api scope to provided

* Make Gson static field
2017-03-11 22:27:41 +01:00

35 lines
765 B
Java

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> {
private static Gson gson = new Gson();
@Override
public Message decode(String s) throws DecodeException {
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
}
}