<html><head></head><body>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?<br>
<br>
Yes, slightly less efficient, but more respectful of the API and likely better abstraction....<br>
-- <br>
Sent from my Android phone with K-9 Mail. Please excuse my brevity.<br><br><div class="gmail_quote">Hraban Luyat <hraban@0brg.net> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre style="white-space: pre-wrap; word-wrap:break-word; font-family: sans-serif">Hello,<br /><br />As far as I understand the decoder API it is mostly geared towards<br />defining the decoder for an entire snippet in one place. I would like<br />to know what the recommended way is to separate the definition of the<br />decoder over separate modules.<br /><br />The semantics of my incoming messages are thus:<br /><br />object:<br /> - "type": string denoting the type<br /> - "payload": type-specific payload<br /><br />I want to create a decoder that only extracts the type and uses that<br />to determine which decoder to send the payload to. Then it continues<br />with whatever lisp object the decoder returned.<br /><br />What I thought would be appropriate is to create a generic function;<br /><br />(defgeneric json->data (type payload))<br /><br />and then simply register decoders as follows:<br /><br />(defmethod json->data ((type (eq :foo)) payload)<br /> "Decode message
of type foo."<br /> ...)<br /><br />(defmethod json->data ((type (eq :bar)) payload)<br /> "Decode message of type bar."<br /> ...)<br /><br />But now I am not really sure how to glue this together. What would you<br />recommend? Is this the right frame of mind at all or should I take a<br />totally different approach?<br /><br />Thanks!<br /><br />Hraban<br /><br /><hr /><br />cl-json-devel mailing list<br />cl-json-devel@common-lisp.net<br /><a href="http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cl-json-devel">http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cl-json-devel</a><br /></pre></blockquote></div></body></html>