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
This commit is contained in:
parent
86eb549596
commit
84c71b3dbf
|
@ -8,9 +8,11 @@ import com.baeldung.model.Message;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
public class MessageDecoder implements Decoder.Text<Message> {
|
public class MessageDecoder implements Decoder.Text<Message> {
|
||||||
|
|
||||||
|
private static Gson gson = new Gson();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Message decode(String s) throws DecodeException {
|
public Message decode(String s) throws DecodeException {
|
||||||
Gson gson = new Gson();
|
|
||||||
Message message = gson.fromJson(s, Message.class);
|
Message message = gson.fromJson(s, Message.class);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,11 @@ import com.baeldung.model.Message;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
public class MessageEncoder implements Encoder.Text<Message> {
|
public class MessageEncoder implements Encoder.Text<Message> {
|
||||||
|
|
||||||
|
private static Gson gson = new Gson();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String encode(Message message) throws EncodeException {
|
public String encode(Message message) throws EncodeException {
|
||||||
Gson gson = new Gson();
|
|
||||||
String json = gson.toJson(message);
|
String json = gson.toJson(message);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue