From df994f324004f6284c415da37c24c1d5f99c56aa Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sun, 16 Jun 2024 22:25:59 -0500 Subject: [PATCH] JSON tweaks: Objects-in-objects, ignore nil slots --- src/activity-vocabulary.lisp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/activity-vocabulary.lisp b/src/activity-vocabulary.lisp index d2bc841..94e816b 100644 --- a/src/activity-vocabulary.lisp +++ b/src/activity-vocabulary.lisp @@ -100,8 +100,9 @@ CLASS’es 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 @@ CLASS’es 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))