[Cl-perec-devel] JSON serialization

Mihai Bazon mihai at bazon.net
Sat Sep 19 09:59:52 UTC 2009


Hi folks,

I'm trying to use a custom keyword in slot definitions (:serializable)
that would let a base class know whether that slot is supposed to be
serialized in JSON (to implement a generic way to JSONize perec
objects).

Defclass-star allows arbitrary keywords, but the problem is that when
defassociation is called, the values of :serializable passed in class
definition are lost. What happens, I think, is that the class gets
redefined but the system uses only slot keywords declared in
persistent-slot-definition and subclasses.

Talked to some folks on the IRC, the general opinion is to modify
cl-perec, but I don't like to use modified versions of libraries I
didn't wrote :).  So my question is, if I implement generic support for
encode-json in cl-perec, would it be acceptable to include the patch in
the official repository?  This support would mean the following:

* keyword :serializable (or :json?) supported in slot definitions with
  one of the following values: :always (default), :light, :heavy,
  :never

* (encode-json persistent-object stream) will write a JSON
  representation of the object that includes :always and :light slots
  (and the OID)

* (let ((prc::*full-json* t)) (encode-json object stream)) will include
  the :heavy slots as well

* associations will be serialized as OID (for 1-1) or [ OID, OID ... ]
  (for 1-n, m-n)

All of the above is pretty easy to do without touching perec, but I just
miss the :serializable keyword support.  (or maybe I just don't know
enough Lisp and there's an easy way around it?  I did investigate
creating my own metaclass and slot definition classes, but concluded
that it's too much boilerplate code for such simple functionality)

Cheers,
-Mihai



More information about the cl-perec-devel mailing list