Skip to content

Fix `replacer' is not called when writing objects#78

Open
fstamour wants to merge 1 commit intoZulu-Inuoe:developfrom
fstamour:replacer
Open

Fix `replacer' is not called when writing objects#78
fstamour wants to merge 1 commit intoZulu-Inuoe:developfrom
fstamour:replacer

Conversation

@fstamour
Copy link
Copy Markdown
Contributor

@fstamour fstamour commented Jul 23, 2025

See #79


  • no tests
  • an if with a progn
  • might be more performant if the if replacer is moved outside the loop, but it might not

Otherwise, is that good?


Here's the code to repro the bug:

(defun json-replacer (key value)
  (declare (ignorable key))
  (typecase value
    (null t)
    (symbol (values t (string-downcase value)))
    (t t)))


;;; stringify'ing a hash-table: works

(let ((ht (make-hash-table)))
  (setf (gethash :slot ht) :keyword)
  (com.inuoe.jzon:stringify
   ht
   :replacer 'json-replacer))
;; => "{\"slot\":\"keyword\"}"
;; as expected


;;; stringify'ing an object: doesn't work

(defclass object () ((slot :initarg :slot)))

(com.inuoe.jzon:stringify
 (make-instance 'object :slot :keyword)
 :replacer 'json-replacer)
;; => "{\"slot\":\"KEYWORD\"}"

@fstamour fstamour changed the title Fix `replacer' is not called when writing objects #79: Fix `replacer' is not called when writing objects Jul 23, 2025
@fstamour fstamour changed the title #79: Fix `replacer' is not called when writing objects Fix `replacer' is not called when writing objects Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant