B4J Question Serializator error

giggetto71

Active Member
Licensed User
Longtime User
Hi,
I am using a B4XSerializator object to convert a payload I get from a MQTT message.
In the mqttclient_messageArrived event handler I get an error I can't fix.
Basically the below line crashes
Code: Copy
Dim obj As Object = serializator.ConvertBytesToObject(Payload) ' this one crashes
Dim s As String = obj
select s
   case "start"
      timer1.Enabled = True
   case "stop"
      timer1.enabled = False
.........

serializator is defined in the Process_Global as

Code: Copy
Dim serializator As B4XSerializator

while Payload is a parameter of the handler
Code: Copy
Sub mqttclient_MessageArrived (Topic As String, Payload() As Byte)

The crash message is:

java.util.zip.ZipException: incorrect header check
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:122)
at java.io.DataInputStream.readByte(DataInputStream.java:265)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readByte(B4XSerializator.java:131).....
.........



It really seems a trivial mistake but I can't understand what's wrong. Can anyone help?
thanks!!
pierluigi
 
I may be totally wrong (as I have not used B4XSerializator or mqtt), but unless the object has been serialized by the sender, you cannot just convert an array of bytes back to an object, as the information about what type of object is encoded will be missing.
 
Upvote 0
Back
Top