如何在Clojure中将类强制转换为对象?
例如:
这堂课:
#app.DatabaseEvent{:token #uuid "58262681-400c-43a7-96d3-93c9b8a8ab11", :timestamp #inst "2018-03-27T12:02:07.558000000-00:00", :message "hello world!", :state "info"}
对此对象:
{:token #uuid "58262681-400c-43a7-96d3-93c9b8a8ab11", :timestamp #inst "2018-03-27T12:02:07.558000000-00:00", :message "hello world!", :state "info"}
答案 0 :(得分:1)
我应该使用这个:https://clojuredocs.org/clojure.core/into
(into {} #app.DatabaseEvent{:token #uuid "58262681-400c-43a7-96d3-93c9b8a8ab11", :timestamp #inst "2018-03-27T12:02:07.558000000-00:00", :message "hello world!", :state "info"})
答案 1 :(得分:0)
使用(bean对象)
(def d (java.util.Date.))
=> #'user/d
d
=> #inst "2018-03-27T18:30:13.718-00:00"
(bean d)
=> {:day 2, :date 27, :time 1522175413718, :month 2, :seconds 13, :year 118, :class java.util.Date, :timezoneOffset 0, :hours 18, :minutes 30}