Serialize the object to a plist
This commit is contained in:
parent
42b08badb9
commit
7909196650
1 changed files with 13 additions and 0 deletions
|
@ -100,3 +100,16 @@
|
|||
(duration :initarg :duration
|
||||
:accessor object-duration
|
||||
:documentation "When the object describes a time-bound resource, such as an audio or video, a meeting, etc, the duration property indicates the object's approximate duration.")))
|
||||
|
||||
(defgeneric to-plist (object)
|
||||
(:documentation "Serialize an object to a plist. This function is independent from any JSON library, allowing serialization to a plist which can then be used to create a JSON string with any desired library."))
|
||||
|
||||
(defmethod to-plist ((obj object))
|
||||
(loop :for slot :in (sb-mop:class-slots (class-of obj))
|
||||
:for slot-name = (sb-mop:slot-definition-name slot)
|
||||
:when (slot-boundp obj slot-name)
|
||||
append (list (intern (symbol-name slot-name) "KEYWORD")
|
||||
(let ((value (slot-value obj slot-name)))
|
||||
(if (typep value 'object)
|
||||
(to-plist value)
|
||||
value)))))
|
||||
|
|
Loading…
Add table
Reference in a new issue