-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Issue with model and json-encode #83
Comments
I don't know why json-encode expects simple-string, but here is what I do:
|
Thank you @knobo for the function, but seems that nothing is changed, the same error is thrown:
Yesterday I found a workaround using a custom (defun render-book-as-json (book)
(setf (getf (response-headers *response*) :content-type) "application/json")
(let ((json
(with-output-to-string*
(with-object
(write-key-value "id" (book-id book))
(write-key-value "title" (coerce (book-title book) 'simple-string))
(write-key-value "author" (coerce (book-author book) 'simple-string))
(write-key-value "created" (book-created book))))))
(setf (response-body *response*) json)))
(render-book-as-json my-model-from-db) Then I've found a better, at least from my point of view, solution using a custom datafly inflation function: (defun chars-vector-to-string (val)
(etypecase val
(null nil)
((vector character) (coerce val 'simple-string))))
@model
(defstruct (book (:inflate created #'datetime-to-timestamp)
(:inflate (title author) #'chars-vector-to-string))
id
title
author
created) Using this I can just evaluate I don't now if this is an issue or if there is something wrong or missing in my code I'm using hunchentoot and postgres 9.5.2. |
Ref this: |
Nice catch @knobo. Seems that So, since caveman isn't using jonhatan directly, but it's using datafly |
I'm trying Caveman2 with a postgres db and a simple books collection:
I'm expecting to get a book by id with this function:
But it doesn't work as expected:
Seem that the slot value
title
is a(VECTOR CHARACTER 64)
.I've also tried using a
varchar
column instead oftext
but the same error is thrown.Thank you for your work.
The text was updated successfully, but these errors were encountered: