Ensure that primitive values are cast to the correct types in serialization
This commit is contained in:
parent
0f227ac6f8
commit
e00e62f996
1 changed files with 13 additions and 2 deletions
|
|
@ -255,10 +255,21 @@
|
||||||
[obj type scope]
|
[obj type scope]
|
||||||
(type-dispatch type)))
|
(type-dispatch type)))
|
||||||
|
|
||||||
|
(def ^:private primitive-cast
|
||||||
|
"Map from primitive type names to the function to cast it to a primitive."
|
||||||
|
{::byte byte
|
||||||
|
::short short
|
||||||
|
::int int
|
||||||
|
::long long
|
||||||
|
::long-long long
|
||||||
|
::char char
|
||||||
|
::float float
|
||||||
|
::double double})
|
||||||
|
|
||||||
(defmethod serialize* :default
|
(defmethod serialize* :default
|
||||||
[obj type _scope]
|
[obj type _scope]
|
||||||
(if (primitive-type type)
|
(if-let [prim (primitive-type type)]
|
||||||
obj
|
((primitive-cast prim) obj)
|
||||||
(throw (ex-info "Attempted to serialize a non-primitive type with primitive methods"
|
(throw (ex-info "Attempted to serialize a non-primitive type with primitive methods"
|
||||||
{:type type
|
{:type type
|
||||||
:object obj}))))
|
:object obj}))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue