Open zhuoran opened 9 years ago
Hi @zhuoran did you find any solution for this problem
Hi @zhuoran, I have the same problem, do you fixed it??
Android client use json parser is "org.json",when emit message,you should like this:
ChatEvent data = new ChatEvent(); mSocket.emit("message", new JSONObject(data));
@jiangbaojun is right, i also added a correction to his tho
mSocket.emit("message", new JSONObject(new Gson().toJson(data)));
try and convert the object you are trying to send to a string using GSON library
my Solution: the bean add constructor by createFromString like this:
`class TestBean {
private String x;
private String y;
private String z;
public TestBean() {}
public TestBean(String beanStr) {
// StdValueInstantiator.createFromString
// _fromStringCreator
JSONObject parseObject = JSON.parseObject(beanStr);
setX(parseObject.getString("x"));
setY(parseObject.getString("y"));
setZ(parseObject.getString("z"));
}`
you can grab the packet By wrieshark Look at the differences between JS and Android package
the package Sketch Map:
JS-Client package:
java-client package:
@jingzhongyue Hey. I'm experiencing the same problem as he does. Except that it's the JS client that doesn't work for me. Would you mind explaining that solution, as I'm not quite sure what you mean?
In my case I used JacksonJsonSupport to parse json object
when I received user data from ChatEventListener and I always get a error!
This problem occurs only when the Android client, JavaScript client has no problem
Android Client Code Both of these two methods are parse failed
Any Idea for this?
Thx
···java [com.corundumstudio.socketio.JsonSupportWrapper]-[ERROR] Can't read value: ["message","{\"action\":1,\"content\":\"ffc\",\"date\":1437811543560,\"from\":1,\"nickName\":\"test\",\"roomId\":\"1001\",\"uid\":\"AYGQNVGEQOZ95POR\"}"] for type: class com.corundumstudio.socketio.protocol.Event com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.xxx.chat.protocol.ChatEvent] from String value ('{"action":1,"content":"ffc","date":1437811543560,"from":1,"nickName":"test","roomId":"1001","uid":"AYGQNVGEQOZ95POR"}'); no single-String constructor/factory method at [Source: io.netty.buffer.ByteBufInputStream@21a1f581; line: 1, column: 11] at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148) at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:757) at com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks(ValueInstantiator.java:277) at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:289) at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1133) at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:135) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:126) at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3023) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1637) at com.corundumstudio.socketio.protocol.JacksonJsonSupport$EventDeserializer.deserialize(JacksonJsonSupport.java:194) at com.corundumstudio.socketio.protocol.JacksonJsonSupport$EventDeserializer.deserialize(JacksonJsonSupport.java:155) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3051) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2192) at com.corundumstudio.socketio.protocol.JacksonJsonSupport.readValue(JacksonJsonSupport.java:337) at com.corundumstudio.socketio.JsonSupportWrapper.readValue(JsonSupportWrapper.java:52) at com.corundumstudio.socketio.protocol.PacketDecoder.parseBody(PacketDecoder.java:303) at com.corundumstudio.socketio.protocol.PacketDecoder.decode(PacketDecoder.java:184) at com.corundumstudio.socketio.protocol.PacketDecoder.decodePackets(PacketDecoder.java:150) at com.corundumstudio.socketio.handler.InPacketHandler.channelRead0(InPacketHandler.java:65) at com.corundumstudio.socketio.handler.InPacketHandler.channelRead0(InPacketHandler.java:36) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:187) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846) at com.corundumstudio.socketio.transport.WebSocketTransport.channelRead(WebSocketTransport.java:94) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at com.corundumstudio.socketio.transport.PollingTransport.channelRead(PollingTransport.java:109) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at com.corundumstudio.socketio.handler.AuthorizeHandler.channelRead(AuthorizeHandler.java:115) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:108) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:182) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) at java.lang.Thread.run(Thread.java:745) 2015-07-25 16:03:05.042 [com.corundumstudio.socketio.handler.InPacketHandler]-[ERROR] Error during data processing. Client sessionId: d2a0be61-0ab0-437f-9c1e-2b325ae316d2, data: java.lang.NullPointerException at com.corundumstudio.socketio.protocol.PacketDecoder.parseBody(PacketDecoder.java:304) at com.corundumstudio.socketio.protocol.PacketDecoder.decode(PacketDecoder.java:184) at com.corundumstudio.socketio.protocol.PacketDecoder.decodePackets(PacketDecoder.java:150) at com.corundumstudio.socketio.handler.InPacketHandler.channelRead0(InPacketHandler.java:65) at com.corundumstudio.socketio.handler.InPacketHandler.channelRead0(InPacketHandler.java:36) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:187) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846) at com.corundumstudio.socketio.transport.WebSocketTransport.channelRead(WebSocketTransport.java:94) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at com.corundumstudio.socketio.transport.PollingTransport.channelRead(PollingTransport.java:109) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at com.corundumstudio.socketio.handler.AuthorizeHandler.channelRead(AuthorizeHandler.java:115) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:108) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:182) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) at java.lang.Thread.run(Thread.java:745)