在pom文件中引入:
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
使用举例:
try {
System.out.println("存在失活的节点! 关键字: " + key);
WebSocketServer.sendInfo( new Gson().toJson(new WebSocketCommon(1,key,"下线通知")));
} catch (IOException e) {
e.printStackTrace();
}