Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yason has problem encoding "pure" cons #80

Open
jcguu95 opened this issue Feb 15, 2023 · 2 comments
Open

yason has problem encoding "pure" cons #80

jcguu95 opened this issue Feb 15, 2023 · 2 comments

Comments

@jcguu95
Copy link

jcguu95 commented Feb 15, 2023

Yason does not encode a lisp pure cons (a pure cons is a cons whose cdr is not a cons) into json correctly. For example, an attempt to encode (1 . 2) returns the error.

* (ql:quickload :yason)
* (yason:encode (cons 1 2) *standard-output*)
#<THREAD "main thread" RUNNING {7008680273}>:
  The value
    2
  is not of type
    LIST

This is because (defmethod encode ((object list) ..) treats "pure cons" as lists too,
which seems to be a "feature" of common lisp.

* (defmethod test ((object list)) (pprint object))
#<STANDARD-METHOD COMMON-LISP-USER::TEST (LIST) {7005484C83}>
* (test (cons 1 2))
(1 . 2)

Solutions:

  1. Make it more explicit that "pure cons" are not supported.
  2. Support encoding pure cons.
@jcguu95 jcguu95 changed the title yason has problem encoding cons yason has problem encoding "pure" cons Feb 15, 2023
@phmarek
Copy link
Owner

phmarek commented Feb 15, 2023

Well, yeah; you're right.

But it's not just plain cons cells -- what should we do for '(1 2 . 3)? Walk the entire input list to decide whether it's a proper list or not, and switch behaviour? Or just serialize '(1 2 . 3) the same as '(1 2 3)?

@hanshuebner
Copy link
Collaborator

If you represent your data as lists or cons trees, I'd recommend that you use a custom serialization function instead of trying to guess the actual type of the cons that is being serialized.

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

No branches or pull requests

3 participants