Share My Creation Json to Class / Class to Jason / Class to map /Map to class ? possible ? rigth

Recently, I encountered a big pitfall; I needed to connect to an API with many, but many tables from a b4j / b4x application; My base classes to handle the data were defined simply with type; They were only objects without methods.

I had something like 240 tables and 240 classes or models, which I should set and get many times, something quite laborious and the first 30 I gave up, I thought: why isn't there a library like gson, that made me set in my variables or convert my cases to maps or lists ?.

Researching and paying code I managed to develop a portion of code, which I share.

It works correctly with most json objects, it can effectively convert the primary object.

example :

Define object:
'Simple type
Type TObject (Data As Int, name As String)
Type TData(Nombre As String,Edad As Int,datos2 As Map, datos As List)

Dim jsonObject =  String = $"{"Nombre":"Luis","Edad":27, "datos":["1","2","3"], "datos2":{"Nombre":"Luis","Edad":27} }"$
Dim People as TData
People = Class2Utils.Json2Class(jsonObject,People)
' other
Dim MapTest as Map = Class2Map(People)

It is very simple to use , but powerfull code!!


  • Class2Utils.bas
    4 KB · Views: 129