Specifiy top-level json class in lisp

Ernesto Alfonso erjoalgo at gmail.com
Sat Oct 13 19:27:06 UTC 2018


Hi,

I find the concept of allowing the remote party to specify the lisp
class/package into which a JSON object should be decoded interesting. I
think it allows for objects at any nesting level to be decoded to the
correct lisp class and can be powerful. In my opinion this also introduces
some coupling of the internal service implementation, like class and
package names, with the remote client. But it also requires control over
the remote JSON object structure, which may work for a JS script that is
owned by the same service, but doesn't seem to work for a third-party
service API.

In my case I'm trying to use cl-json to decode several types of third-party
service API's objects, e.g. an oauth server's response, a geocoding
response, etc, and I'd like for cl-json to decode the class for me, instead
of either

- doing a manual transformation for each object,
- adding a json-to-class utility outside of cl-json,
- pre-processing the JSON object to add the expected "prototype" fields
before cl-json:decode, which seems like a hack

Basically, I'd like to know if I can do something like:

    (cl-json:decode-json-from-source *stream* my-class)

Is this possible in CL-JSON?

I am also aware of JSON-MOP, but it currently doesn't support inherited
class slots and I'd like to avoid introducing another dependency just to
decode to my intended lisp object.

Thanks,

Ernesto
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cl-json-devel/attachments/20181013/a9260577/attachment.html>


More information about the cl-json-devel mailing list