Hello,
I'm trying to make a generic serialize/deserialize mechanism through JSON (to serialize/deserialize custom types). It seems this is not working. Am I doing something wrong or is this generally impossible ?
This is an example
the last log causes:
java.lang.RuntimeException: Field: FirstName not found in: java.lang.String
I'm trying to make a generic serialize/deserialize mechanism through JSON (to serialize/deserialize custom types). It seems this is not working. Am I doing something wrong or is this generally impossible ?
This is an example
B4X:
...
Sub Process_Globals
Type CustomerType (FirstName As String, LastName As String)
End Sub
...
Dim cst As CustomerType, cstList As List
cst.Initialize
cst.FirstName = "John"
cst.LastName = "Doe"
cstList.Initialize
cstList.Add(cst)
'Serialize list of customer (containing a single customer)
Dim gen As JSONGenerator
gen.Initialize2(cstList)
Log (gen.ToString)
'Deserialize the JSON string
Dim pars As JSONParser
pars.Initialize(gen.ToString)
Dim customers As List = pars.NextArray
Dim customer As CustomerType = customers.Get(0)
Log(customer.FirstName)
the last log causes:
java.lang.RuntimeException: Field: FirstName not found in: java.lang.String