Skip to content

Commit 84c71b3

Browse files
Alex Vargaszhendrikse
authored andcommitted
Bael 389 - Making Gson field in both classes static (eugenp#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
1 parent 86eb549 commit 84c71b3

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

java-websocket/src/main/java/com/baeldung/websocket/MessageDecoder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import com.google.gson.Gson;
99

1010
public class MessageDecoder implements Decoder.Text<Message> {
11+
12+
private static Gson gson = new Gson();
13+
1114
@Override
1215
public Message decode(String s) throws DecodeException {
13-
Gson gson = new Gson();
1416
Message message = gson.fromJson(s, Message.class);
1517
return message;
1618
}

java-websocket/src/main/java/com/baeldung/websocket/MessageEncoder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import com.google.gson.Gson;
99

1010
public class MessageEncoder implements Encoder.Text<Message> {
11+
12+
private static Gson gson = new Gson();
13+
1114
@Override
1215
public String encode(Message message) throws EncodeException {
13-
Gson gson = new Gson();
1416
String json = gson.toJson(message);
1517
return json;
1618
}

0 commit comments

Comments
 (0)