-
Notifications
You must be signed in to change notification settings - Fork 9
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
Example for consuming a list of objects #3
Comments
There's no API for it in json-mop. You'll have to parse your JSON response with Yason into a list of hash tables, iterate over it and calling Maybe there should be an API for it. I feel bad for not maintaining this library all these years, I really need to do something about that. |
i had the same issue, and managed to implement it with a loop. then i was reading up a little more on initializing, and discovered the but it doesn't work, even though the is there some way that my or could there be something else in seems like |
Consuming list / vectors can be implemented by adding these two additional (defmethod json-to-clos ((input list) class &rest initargs)
(declare (ignore initargs))
(mapcar (lambda (element)
(json-to-clos element class))
input))
(defmethod json-to-clos ((input vector) class &rest initargs)
(declare (ignore initargs))
(coerce (json-to-clos (coerce input 'list) class)
'vector)) Then we can parse an list object with What do you think @gschjetne ? |
My CL is a bit rusty, but could we specialize on sequence instead, and kill two birds with one stone? |
Sure we can also do it with a method specialized on sequence, such as: (defmethod json-to-clos ((input sequence) class &rest initargs)
(declare (ignore initargs))
(etypecase input
(list
(mapcar (lambda (element)
(json-to-clos element class))
input))
(vector
(map 'vector
(lambda (element)
(json-to-clos element class))
input)))) |
I can succesfully consume a class
person
from the according json format, but how do I invoke json-to-clos if my json endpoint returns a list ofperson
. Being fairly new to Common Lisp I do not grokk yet how to provide the according class information.The text was updated successfully, but these errors were encountered: