[Cuis-dev] JSON encoding and decoding

Mark Volkmann r.mark.volkmann at gmail.com
Sun Jun 16 16:25:36 PDT 2024


The WebClient package can generate JSON from a Dictionary.
Does Cuis provide a method that generates a Dictionary from the instance
properties of an arbitrary Object?
I looked for a method in Object or Dictionary that does that conversion and
couldn't find one.

On Sun, Jun 16, 2024 at 6:16 PM Mark Volkmann <r.mark.volkmann at gmail.com>
wrote:

> On Sun, Jun 16, 2024 at 5:33 PM Mariano Montone via Cuis-dev <
> cuis-dev at lists.cuis.st> wrote:
>
>> El 16/6/24 a las 18:52, Mark Volkmann via Cuis-dev escribió:
>>
>> There are methods to encode and decode JSON in the WebClient package
>> inside the WebUtils class. But they seem incomplete and/or broken. For
>> example, the class method `#jsonObj:on:` does not handle arbitrary objects
>> by using reflection to discover their instance properties. That's a feature
>> I want. I suppose I can implement that myself, but this seems like
>> something someone most likely already implemented. Is there another package
>> for JSON that is recommended?
>>
>> Yes.
>>
>> Feature require: 'JSON'.
>>
>
> After running that in a Workspace I entered this where dog is variable
> that holds an object from my Dog class that has the instance variables id,
> name, and breed:
>
> s := Json render: dog
>
> That gives me MessageNotUnderstood: VDog>>jsonWriteOn:.
>
> Why does it expect me to implement that method in my Dog class? I expect
> it to just use reflection to get all the instance variables of the object
> and build JSON from them.
>
> I really wish it was more common for Smalltalk packages to provide
> documentation on their usage and some example code.
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>


-- 
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240616/8aff0ab3/attachment.htm>


More information about the Cuis-dev mailing list