B4J Question ConvertObjectToBytes ClassCastException

kevv

New Member
Licensed User
Longtime User
Hi
the communication between my server and client looks like this

but if the client sends wrong data = ClassCastException
how can i check is result correct?

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Type RegData (Id As String, Name As String, Data As String)
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
    
    ClientApp
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub





Sub ClientApp()
    
    Dim Obj As RegData
    Obj.Id = "id"
    Obj.Name = "name"
    Obj.Data = "data"
    
    Dim WrongData As String = "CLIENT_SEND_WRONGDATA"
    
    
    Dim ser As B4XSerializator
    'Dim b() As Byte = ser.ConvertObjectToBytes(Obj)
    Dim b() As Byte = ser.ConvertObjectToBytes(WrongData)
    
    ServerApp(b)
    
End Sub




Sub ServerApp(b() As Byte)
    
    
    Dim ser As B4XSerializator
    Dim result As RegData = ser.ConvertBytesToObject(b)
    Log(result.Name)
    

End Sub
 
Top