manish manish - 1 year ago 131
Java Question

How to get Object from MQTT message payload

On receiving mqtt message I am trying to get Object from payload (byte[])

Object ob = SerializationUtils.deserialize(message.getPayload());

I am getting:

org.apache.commons.lang.SerializationException: invalid stream header: 7B22736E
at org.apache.commons.lang.SerializationUtils.deserialize(
at org.apache.commons.lang.SerializationUtils.deserialize(

Answer Source

You need a JSON parser not the Apache Commons Serialization library.

Something like the parser

JSONObject obj = new JSONObject(msg.toString());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download