I am trying to convert JSON file to thrift binary format to save storage and network bandwidth. this is irrelevant to my question. But want to describe its context.
So let say, I have a map from json, and Java Class Event
(def m
{"a" 1
"b" 2})
java class
package my-test;
class Event {
public String a;
public String b;
public void setA(String a) { this.a = a; }
public void setB(String b) { this.b = b; }
}
How can I get a Event object with value m?
P.S.
tried to use call-method* mentioned in https://groups.google.com/forum/#!topic/clojure/YJNRnGXLr2I
(defn call-method* [obj m & args]
(eval `(. ~obj ~(symbol m) ~@args)))
but Can't embed object in code, maybe print-dup not defined raised. I have no idea why.
=> (def o (Event.))
=> (call-method* o "setA" "1")
CompilerException java.lang.RuntimeException: Can't embed object in code,
maybe print-dup not defined: mytest.Event@681d891, compiling:
(/private/var/folders/hd/xxl2lfmn5wggspxwwtk2r2zr0000gn/T/form-init2883112335729429073.clj:1:1)
P.S.
This Question Dynamic method calls in a Clojure macro? is more appropriate to read.
thrift generated java classwith clojure.java.data. It didn't worked withclojure.java.data/to-javabecausethrift generated java classis not abeanby default.thrift --gen java:beans a.thriftworked for me.