trinopoty / socket.io-server-java

Socket.IO Server Library for Java
Other
179 stars 50 forks source link

Broadcasting Java objects #20

Closed manikmagar closed 3 years ago

manikmagar commented 3 years ago

When emitting events with https://github.com/socketio/socket.io-client-java, Java objects (eg. Map) can be sent to server without any JSON conversion. On server side, it is converted to an instance of JSONObject.

But when broadcasting from server, java object isn't allowed. PacketUtils.isPacketDataValid(array) throws error when array contains java objects. It is expecting the literal types or JSONObject/JSONArray. For consistency, should it allow broadcasting Java objects similar to client? Looking at the client's IO Parser, it is doing the same decoding as server. So it should be able to read those objects same way as server.

manikmagar commented 3 years ago

Correction - Client does not support all java objects but Map works probably because of the toString implementation of Map is compliant with JSONTokenizer for JSONObject.

trinopoty commented 3 years ago

Only JSONObject and JSONArray is supported at the moment. However, there are plans to allow support for arbitrary json serialization libraries such as Gson or Jackson. Keep a lookout for it.