[cl-json-devel] Guidance requested: how to dispatch members to external decoders?

Robert P. Goldman rpgoldman at sift.info
Sun Aug 14 16:19:36 UTC 2011


Is it necessary to do this relatively complex thing, or can you simply decode the JSON object in a standard way and then decode the JSON object into your own object?

Yes, slightly less efficient, but more respectful of the API and likely better abstraction....
-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Hraban Luyat <hraban at 0brg.net> wrote:

Hello,

As far as I understand the decoder API it is mostly geared towards
defining the decoder for an entire snippet in one place. I would like
to know what the recommended way is to separate the definition of the
decoder over separate modules.

The semantics of my incoming messages are thus:

object:
- "type": string denoting the type
- "payload": type-specific payload

I want to create a decoder that only extracts the type and uses that
to determine which decoder to send the payload to. Then it continues
with whatever lisp object the decoder returned.

What I thought would be appropriate is to create a generic function;

(defgeneric json->data (type payload))

and then simply register decoders as follows:

(defmethod json->data ((type (eq :foo)) payload)
"Decode message of type foo."
...)

(defmethod json->data ((type (eq :bar)) payload)
"Decode message of type bar."
...)

But now I am not really sure how to glue this together. What would you
recommend? Is this the right frame of mind at all or should I take a
totally different approach?

Thanks!

Hraban

_____________________________________________

cl-json-devel mailing list
cl-json-devel at common-lisp.net
http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cl-json-devel

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


More information about the cl-json-devel mailing list