Skip to content
Snippets Groups Projects
Verified Commit 51afb85d authored by Eric Diethelm's avatar Eric Diethelm
Browse files

Handle empty lists correctly as nil and don't serialize functions.

To serialize function, see trivial-action.
parent f2567f6b
No related branches found
No related tags found
No related merge requests found
Pipeline #50078685 passed
......@@ -11,6 +11,10 @@ Implementations for built-in types already exist. The user might extend with met
(declare (type stream stream))
(format stream "<>"))
(defmethod serialize ((obj function) stream)
(declare (type stream stream))
(serialize nil stream))
(defmethod serialize ((obj (eql t)) stream)
(declare (type stream stream))
(princ #\T stream))
......@@ -102,7 +106,9 @@ If *CLASS* is non-nil and represents a class, an instance of it is returned. Oth
(declare (type list parsed-l))
(return-from create-symbol-from-json
(case (car parsed-l)
(List (mapcar #'(lambda (elm) (create-symbol-from-json elm base-class constructors)) (cdr parsed-l)))
(List (if (eq 1 (length parsed-l))
nil
(mapcar #'(lambda (elm) (create-symbol-from-json elm base-class constructors)) (cdr parsed-l))))
(Array (let ((arr (make-array (length (the list (cdr parsed-l))))))
(loop for elm in (cdr parsed-l)
for i of-type fixnum = 0 then (1+ i)
......@@ -186,8 +192,9 @@ If *CLASS* is non-nil and represents a class, an instance of it is returned. Oth
(let* ((types (if (listp raw-type) (cdr raw-type) (list raw-type)))
(data (get-data-for-slot name parsed))
(unk (gensym))
(res (loop for type in (remove 'null types)
with r = nil
with r = unk
until
(setf r (if (and
(typep data type)
......@@ -196,7 +203,7 @@ If *CLASS* is non-nil and represents a class, an instance of it is returned. Oth
data
(create-symbol-from-json data (find-class type) constructors)))
finally (return r))))
(unless res
(when (eq unk res)
(error "Could not match value to type."))
(list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment