I think you will find this is as short as it can possibly go before it starts to become unmaintainable...
The current GitHub version will only serialise and deserialise to and from class based objects.
I do however have several other solutions in the unofficial version which will efficiently serialise and deserialise to and from globals. I also have a pollyfill solution for DynamicObject and DynamicArray that uses a type mixer class that would allow older versions of Cache to work with these classes now.
However, I've not used these in production, only unit tested. I am happy to release them if there is a need / someone is willing to collaborate on production level testing and debugging.
In general +1 for the generic boiler plate approach.
In terms of a generic JSON solution is could do with some additional type checks to make sure they are output correctly, e.g. booleans as true / false / null, empty numbers being returned as null and not empty string etc.
So just for booleans as an untested example you might replace...
The alternative, if just going from SQL to a serialised JSON string could be to just use SQL and JSON_ARRAYAGG as per the examples here...
To leave a comment or answer to post please log in
Please log in
To leave a post please log in