pyclj
pyclj copied to clipboard
Decoder does not handle type "object"
I have a response that returns the following syntax
#object[<namespace>.<record> <hex_number> "<edn>"]
Here is a sample output
#object[com.example.funktown.DoubleEntity 0x66c5e52e "{:my/keyword1 :my/keyword2, :keyword3 1462827186240, :my/keyword3 \"This is a string\", :my/key5 #inst \"1970-01-01T00:00:00.000-00:00\"}"]
However, calling clj.loads(data)
with the above fails with the following:
>>> data = '#object[com.example.funktown.DoubleEntity 0x66c5e52e "{:my/keyword1 :my/keyword2, :keyword3 1462827186240, :my/keyword3 \"This is a string\", :my/key5 #inst \"1970-01-01T00:00:00.000-00:00\"}"]'
>>> clj.loads(data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/clj.py", line 407, in loads
result = load(buf)
File "/usr/lib/python2.7/site-packages/clj.py", line 403, in load
return decoder.decode()
File "/usr/lib/python2.7/site-packages/clj.py", line 82, in decode
v = self.__read_token()
File "/usr/lib/python2.7/site-packages/clj.py", line 263, in __read_token
raise ValueError('Unexpected char: "%s" at line %d, col %d' % (c, self.cur_line, self.cur_pos))
ValueError: Unexpected char: "#" at line 1, col 1
I'm not familiar with clojure well enough, but it would be nice to handle the type object
. Or maybe provide function that would return only the the EDN data structure.
Yes this is true, object/record were no supported in this library. Because we cannot find com.example.funktown.DoubleEntity
type on the python side. Perhaps you can transform your clojure object to a map before given it to python.
Changing the clojure object to a map is not an option for what I'm trying to do as there is alot of risk to it.
All clojureobject
type seem to have the same structure.
#object[<namespace> <hex> "<edn>"]
If we receive #object, why not just ignore the next [
, then ignore the <namespace>
and <hex>
. Then return the <edn>
object as a dictionary and ignore the ]
?
Does that sound like a viable solution for you? if so, i can try to post a PR to this project. Please let me know, otherwise I'll fork the repo.