06299969c903 default tip

Allow slot-name-to-json-name to return a symbol too
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 07 May 2024 22:50:12 -0400
parents 96b886c42e68
children (none)
branches/tags default tip
files src/mop.lisp

Changes

--- a/src/mop.lisp	Thu Aug 25 23:10:20 2022 -0400
+++ b/src/mop.lisp	Tue May 07 22:50:12 2024 -0400
@@ -126,6 +126,11 @@
     `(multiple-value-bind (,result ,found) ,form
        (if ,found ,result ,default))))
 
+(defun ensure-string (value)
+  (etypecase value
+    (string value)
+    (symbol (symbol-name value))))
+
 (defun coalesce-most-specific-value (dslots slot-name)
   "Coalesce the most-specific value of `slot-name` from the JSON direct slots.
 
@@ -152,7 +157,7 @@
            (eslot (call-next-method))
            (dslots (remove-if-not #'json-direct-slot-p direct-slots)))
       (setf (json-name eslot) (found-or (coalesce-most-specific-value dslots 'json-name)
-                                        (funcall (slot-name-to-json-name class) name))
+                                        (ensure-string (funcall (slot-name-to-json-name class) name)))
             (json-class eslot) (canonicalize-class-designator
                                  (found-or (coalesce-most-specific-value dslots 'json-class) t))
             (json-initarg eslot) (first (c2mop:slot-definition-initargs eslot))