25 lines
606 B
Java
25 lines
606 B
Java
package ch.usi.inf.sa4.sanmarinoes.smarthut.socket;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.JsonObject;
|
|
import javax.websocket.EncodeException;
|
|
import javax.websocket.Encoder;
|
|
import javax.websocket.EndpointConfig;
|
|
|
|
public class SensorSocketEncoder implements Encoder.Text<JsonObject> {
|
|
private Gson encoder;
|
|
|
|
@Override
|
|
public String encode(JsonObject object) throws EncodeException {
|
|
return encoder.toJson(object);
|
|
}
|
|
|
|
@Override
|
|
public void init(EndpointConfig endpointConfig) {
|
|
encoder = new Gson();
|
|
}
|
|
|
|
@Override
|
|
public void destroy() {}
|
|
}
|