From b2e9e5340dd1502f7b8e8662383d903306e6ac4b Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:01:16 -0500 Subject: [PATCH] Add YASON:ENCODE, for encoding of nested objects --- src/json-ld.lisp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/json-ld.lisp b/src/json-ld.lisp index 866c180..7348dc0 100644 --- a/src/json-ld.lisp +++ b/src/json-ld.lisp @@ -97,6 +97,10 @@ If you would like to change it on an object-level, set the @CONTEXT slot.")) (cdr alist-cell))) (json-ld-etc obj))) +(defmethod yason:encode ((obj json-ld-object) &optional (stream *standard-output)) + (yason:with-output (stream) + (yason:encode-object obj))) + ;;; CLOS definition @@ -198,12 +202,14 @@ into a DEFCLASS format." "Helper-macro for DEFINE-JSON-CLOS-CLASS. This actually defines the YASON-encoder for a JSON-LD node-type. CLASS is the class-name; see DEFINE-JSON-TYPE’s docstring about DIRECT-SLOTS." - (append - `(defmethod yason:encode-slots progn ((obj ,class))) - (mapcar (lambda (slot) - `(when (slot-boundp obj ',(car slot)) - (yason:encode-object-element ,(cadr slot) (slot-value obj ',(car slot))))) - direct-slots))) + `(progn + (defmethod yason:encode-slots progn ((obj ,class)) + ,(append + `(progn) + (mapcar (lambda (slot) + `(when (slot-boundp obj ',(car slot)) + (yason:encode-object-element ,(cadr slot) (slot-value obj ',(car slot))))) + direct-slots)))))