JSONObject payload = new JSONObject();
payload.put("request_id","req_123");
payload.put("content", "xxx");
payload.put("session_id", "sess_123");
JSONObject data = new JSONObject();
data.put("payload",payload);
socket.emit("send",data);
Exception in thread "EventThread" java.lang.ClassCastException: org.json.JSONObject cannot be cast to java.lang.String
at org.example.Main.lambda$main$0(Main.java:79)
at io.socket.emitter.Emitter.emit(Emitter.java:117)
at io.socket.client.Socket.onevent(Socket.java:363)
at io.socket.client.Socket.onpacket(Socket.java:307)
at io.socket.client.Socket.access$100(Socket.java:19)
at io.socket.client.Socket$2$2.call(Socket.java:92)
at io.socket.emitter.Emitter.emit(Emitter.java:117)
at io.socket.client.Manager.ondecoded(Manager.java:361)
at io.socket.client.Manager.access$1200(Manager.java:22)
at io.socket.client.Manager$5.call(Manager.java:355)
at io.socket.parser.IOParser$Decoder.add(IOParser.java:103)
at io.socket.client.Manager$2.call(Manager.java:331)
at io.socket.emitter.Emitter.emit(Emitter.java:117)
at io.socket.engineio.client.Socket.onPacket(Socket.java:556)
at io.socket.engineio.client.Socket.access$1000(Socket.java:29)
at io.socket.engineio.client.Socket$5.call(Socket.java:335)
at io.socket.emitter.Emitter.emit(Emitter.java:117)
at io.socket.engineio.client.Transport.onPacket(Transport.java:124)
at io.socket.engineio.client.Transport.onData(Transport.java:116)
at io.socket.engineio.client.transports.WebSocket.access$100(WebSocket.java:22)
at io.socket.engineio.client.transports.WebSocket$1$2.run(WebSocket.java:71)
at io.socket.thread.EventThread$2.run(EventThread.java:80)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
is it a bug?
the following code works.
import org.json.JSONObject;
JSONObject payload = new JSONObject();
payload.put("request_id","req_123");
payload.put("content", "xxx");
payload.put("session_id", "sess_123");
// JSONObject data = new JSONObject();
// data.put("payload",payload);
// socket.emit("send",data);
socket.emit("send",payload);
it's my fault.
the exception is thrown by the following code.
socket.on("reply", replyArgs -> {
String message = (String) replyArgs[0]; // this line
System.out.println("Received message: " + message);
});
socket.io-client-java version: 2.1.0
import org.json.JSONObject;
JSONObject payload = new JSONObject(); payload.put("request_id","req_123"); payload.put("content", "xxx"); payload.put("session_id", "sess_123"); JSONObject data = new JSONObject(); data.put("payload",payload); socket.emit("send",data);
Exception in thread "EventThread" java.lang.ClassCastException: org.json.JSONObject cannot be cast to java.lang.String at org.example.Main.lambda$main$0(Main.java:79) at io.socket.emitter.Emitter.emit(Emitter.java:117) at io.socket.client.Socket.onevent(Socket.java:363) at io.socket.client.Socket.onpacket(Socket.java:307) at io.socket.client.Socket.access$100(Socket.java:19) at io.socket.client.Socket$2$2.call(Socket.java:92) at io.socket.emitter.Emitter.emit(Emitter.java:117) at io.socket.client.Manager.ondecoded(Manager.java:361) at io.socket.client.Manager.access$1200(Manager.java:22) at io.socket.client.Manager$5.call(Manager.java:355) at io.socket.parser.IOParser$Decoder.add(IOParser.java:103) at io.socket.client.Manager$2.call(Manager.java:331) at io.socket.emitter.Emitter.emit(Emitter.java:117) at io.socket.engineio.client.Socket.onPacket(Socket.java:556) at io.socket.engineio.client.Socket.access$1000(Socket.java:29) at io.socket.engineio.client.Socket$5.call(Socket.java:335) at io.socket.emitter.Emitter.emit(Emitter.java:117) at io.socket.engineio.client.Transport.onPacket(Transport.java:124) at io.socket.engineio.client.Transport.onData(Transport.java:116) at io.socket.engineio.client.transports.WebSocket.access$100(WebSocket.java:22) at io.socket.engineio.client.transports.WebSocket$1$2.run(WebSocket.java:71) at io.socket.thread.EventThread$2.run(EventThread.java:80) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:750)
is it a bug?
the following code works.
import org.json.JSONObject; JSONObject payload = new JSONObject(); payload.put("request_id","req_123"); payload.put("content", "xxx"); payload.put("session_id", "sess_123"); // JSONObject data = new JSONObject(); // data.put("payload",payload); // socket.emit("send",data); socket.emit("send",payload);