Many thanks Dave. That all made sense.
I've just updated my project to use Clojure 1.4 (had to upgrade Noir to 
latest beta) and we are all golden.

Thanks,
Andrew

On Wednesday, 4 July 2012 19:50:34 UTC+1, David Powell wrote:
>
>
>
>
> Please excuse my ignorance. This is the first time I've played with 
>> read-string and the reader...
>>
>> I was trying to serialise some clojure data structures to a database and 
>> then read them back.
>> In the data I have some java.sql.Timestamp data. These get serialised as 
>> #<Timestamp 2012-07-04 00:00:00.000>
>> When trying to read-string this data I get an Unreadable form 
>> RuntimeException.
>>
>
> Anything beginning with #< is unreadable.  If you print a random Java 
> object, then Clojure outputs it using this syntax, which will deliberately 
> cause an error on read; eg:
>
> (prn (Object.))
>
> However, it seems that you are using an old version of Clojure, because 
> as-of Clojure 1.4, Dates, Timestamps, and Calendars now have a readable 
> representation using the new reader.  See 
> https://github.com/clojure/clojure/blob/master/changes.md
>
>  
>
>> user=> (pr-str (java.sql.Timestamp. (.getTime (java.util.Date.))))
>> "#<Timestamp 2012-07-04 15:17:03.959>"
>>
>
> In Clojure 1.4 this will give you:
>
> #inst "2012-07-04T18:46:18.089000000-00:00"
>
> This form (the inst tag - for a date instant, followed by its string 
> represntation), is readable with read-string.
>
> ... there is a gotcha though:
>
> When you read this back, you will, by default, get a java.util.Date, 
> rather than a Timestamp.  If you want instant literals to give you back a 
> timestamp, then you need to rebind the *data-readers* variable to give you 
> back timestamps instead of dates:
>
> (set! *data-readers* (assoc *data-readers* 'inst 
> clojure.instant/read-instant-timestamp))
>
>
> -- 
> Dave
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to