Login  Register

Json encoding

Posted by Vitor Medina Cruz on Mar 20, 2020; 1:20am
URL: https://forum.world.st/Json-encoding-tp5113560.html

Hello,

I know two projects of json encoding/decoding — NeoJson and STON.

In Java I have two most used ones too: Gson and Jackson. Using those I can simply pass any object and it they can convert to a json string, the former can't deal with cycles, the latter can with some little config.

NeoJson seems to be limited to primitives, for example, in Pharo 8 I can't run

NeoJSONWriter toString: (Date today)

Since I got:

NeoJSONMappingNotFound: No mapping found for Date in NeoJSONWriter


STON works fine with 

STON toString: (Date today).

but fail with:

STON toJsonString: (Date today).

Also, STON fails if I try to serialize an object which contains an instance variable pointing to a block closure. I didn't find out how to ignore these instance variable as it is unnecessary for what I need at the moment.

So, which lib for json or some object/string encoding/decoding should I be using on Pharo? Is there something better than those libs? Am I doing something wrong? My experience tells this should be simple, but it is not.

Thanks in advance,
Vitor