Parse even unknown ActivityStreams classes
By means of a *default-class* that is a catch-all.
This commit is contained in:
parent
a2aec426ab
commit
bb361465c3
|
@ -23,7 +23,7 @@
|
||||||
:parse :encode
|
:parse :encode
|
||||||
:define-class-encoders
|
:define-class-encoders
|
||||||
;; Globals
|
;; Globals
|
||||||
:*ap-packages*
|
:*ap-packages* :*default-class*
|
||||||
;; Classes
|
;; Classes
|
||||||
:object
|
:object
|
||||||
;; Slots
|
;; Slots
|
||||||
|
@ -41,6 +41,12 @@ during JSON parsing. The class-name searched for is simply the value of the JSON
|
||||||
object’s “type” key. The package first in the list to export such a symbol
|
object’s “type” key. The package first in the list to export such a symbol
|
||||||
is the winner.")
|
is the winner.")
|
||||||
|
|
||||||
|
(defparameter *default-class* 'activity-servist/activity-streams:object
|
||||||
|
"The class used for ActivityStreams objects found during parsing that don’t
|
||||||
|
have a corresponding class defined. Notably, all keys and values without
|
||||||
|
corresponding slots are placed in the MISC slot.
|
||||||
|
The class you choose should inherit ACTIVITY-SERVIST/ACTIVITY-STREAMS:OBJECT.")
|
||||||
|
|
||||||
;; Private, internal variable.
|
;; Private, internal variable.
|
||||||
(defparameter *@context* nil
|
(defparameter *@context* nil
|
||||||
"Used in YASON:ENCODE to ensure that a single top-level @context can be
|
"Used in YASON:ENCODE to ensure that a single top-level @context can be
|
||||||
|
@ -96,7 +102,8 @@ again and again, by YASON:ENCODE-SLOTS."
|
||||||
|
|
||||||
(defun parse-table (table)
|
(defun parse-table (table)
|
||||||
"Parse a hash-table corresponding to YASON-parsed JSON into an ActivityPub object."
|
"Parse a hash-table corresponding to YASON-parsed JSON into an ActivityPub object."
|
||||||
(let* ((class (car (find-registered-classes (param-case (gethash "type" table)))))
|
(let* ((found-class (car (find-registered-classes (param-case (gethash "type" table)))))
|
||||||
|
(class (or found-class (find-class *default-class*)))
|
||||||
(obj (make-instance class)))
|
(obj (make-instance class)))
|
||||||
(loop for key being each hash-key of table
|
(loop for key being each hash-key of table
|
||||||
for val being each hash-value of table
|
for val being each hash-value of table
|
||||||
|
@ -232,7 +239,11 @@ items in each will be contained in the resultant list."
|
||||||
*ap-packages* list."
|
*ap-packages* list."
|
||||||
(remove-if
|
(remove-if
|
||||||
#'not
|
#'not
|
||||||
(mapcar (lambda (package) (find-symbol (string-upcase str) package))
|
(mapcar (lambda (package)
|
||||||
|
(multiple-value-bind (sym context)
|
||||||
|
(find-symbol (string-upcase str) package)
|
||||||
|
(unless (eq context :inherited)
|
||||||
|
sym)))
|
||||||
*ap-packages*)))
|
*ap-packages*)))
|
||||||
|
|
||||||
(defun find-registered-classes (str)
|
(defun find-registered-classes (str)
|
||||||
|
|
|
@ -54,6 +54,8 @@
|
||||||
|
|
||||||
(in-package #:activity-servist/activity-vocabulary)
|
(in-package #:activity-servist/activity-vocabulary)
|
||||||
|
|
||||||
|
(setq activity-servist/activity-streams:*default-class*
|
||||||
|
'activity-servist/activity-vocabulary:object)
|
||||||
|
|
||||||
|
|
||||||
;;; Macros
|
;;; Macros
|
||||||
|
|
Ŝarĝante…
Reference in New Issue