JSON tweaks: Objects-in-objects, ignore nil slots

This commit is contained in:
Jaidyn Ann 2024-06-16 22:25:59 -05:00
parent c205dff8ea
commit df994f3240

View File

@ -100,8 +100,9 @@ CLASSes slots with JSON keys based on the camel-cased slot name."
(append
`(defmethod yason:encode-slots progn ((obj ,class)))
(mapcar (lambda (slot-key-pair)
`(yason:encode-object-element ,(cdr slot-key-pair)
(slot-value obj ',(car slot-key-pair))))
`(let ((value (slot-value obj ',(car slot-key-pair))))
(when value
(yason:encode-object-element ,(cdr slot-key-pair) value))))
(class-slots-to-camel-cased-strings-alist class))))
@ -112,11 +113,15 @@ CLASSes slots with JSON keys based on the camel-cased slot name."
(defclass-w-accessors object ()
(
attachment attributed-to audience bcc bto cc content context
duration end-time generator icon image in-reply-to location
duration end-time generator icon id image in-reply-to location
media-type name preview published replies start-time summary
tag to updated url
(@context :initform "https://www.w3.org/ns/activitystreams")))
(defmethod yason:encode ((obj object) &optional (stream *standard-output*))
(yason:with-output (stream)
(yason:encode-object obj)))
;; https://www.w3.org/ns/activitystreams#Link
(defclass-w-accessors link ()
(height href hreflang media-type name preview rel width))