Search code examples
google-app-engineweb-applicationsclojuregoogle-cloud-datastoreappengine-magic

How to save a Text property using Clojure and appengine-magic


The body field of a form may contain long text, so the default String property won't do.

Looking for how to make the datastore use Text (this is not part of the entity definition like I recall from the Python version), I found this in the source of the ackbar blog:

(ns <snip>
  (:import (com.google.appengine.api.datastore
            EntityNotFoundException Text)))
<snip>
(ds/save! (Post. url title (Text. body) ts in-feed? category))

But if I do the same, I get: "java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: com.google.appengine.api.datastore.Text"

(One notable difference is that the ackbar I'm looking at uses appengine-magic 0.3.2.)

I also tried as-text as briefly mentioned on https://github.com/gcv/appengine-magic#readme, but (as-text body) in there leads to the same error message as above.


EDIT: Turned out the problem wasn't actually to get a Text property into the store, but to make sense of it when retrieving it. My Submit handler triggers saving and than a reload of the form page, and I failed to think of that. Sorry for the noise.

The way to get the value out without hiccup is (.getValue body).


Solution

  • From the appengine-magic documentation:

    as-text: casts a string to com.google.appengine.api.datastore.Text.

    So you should pass a java.lang.String to as-text.

    (as-text body)