Add YASON:ENCODE, for encoding of nested objects

This commit is contained in:
Jaidyn Ann 2024-08-22 11:01:16 -05:00
parent cc81dee054
commit b2e9e5340d

View File

@ -97,6 +97,10 @@ If you would like to change it on an object-level, set the @CONTEXT slot."))
(cdr alist-cell))) (cdr alist-cell)))
(json-ld-etc obj))) (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 ;;; CLOS definition
@ -198,12 +202,14 @@ into a DEFCLASS format."
"Helper-macro for DEFINE-JSON-CLOS-CLASS. "Helper-macro for DEFINE-JSON-CLOS-CLASS.
This actually defines the YASON-encoder for a JSON-LD node-type. This actually defines the YASON-encoder for a JSON-LD node-type.
CLASS is the class-name; see DEFINE-JSON-TYPEs docstring about DIRECT-SLOTS." CLASS is the class-name; see DEFINE-JSON-TYPEs docstring about DIRECT-SLOTS."
(append `(progn
`(defmethod yason:encode-slots progn ((obj ,class))) (defmethod yason:encode-slots progn ((obj ,class))
,(append
`(progn)
(mapcar (lambda (slot) (mapcar (lambda (slot)
`(when (slot-boundp obj ',(car slot)) `(when (slot-boundp obj ',(car slot))
(yason:encode-object-element ,(cadr slot) (slot-value obj ',(car slot))))) (yason:encode-object-element ,(cadr slot) (slot-value obj ',(car slot)))))
direct-slots))) direct-slots)))))