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]
|
||||
(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
|
||||
[obj type _scope]
|
||||
(if (primitive-type type)
|
||||
obj
|
||||
(if-let [prim (primitive-type type)]
|
||||
((primitive-cast prim) obj)
|
||||
(throw (ex-info "Attempted to serialize a non-primitive type with primitive methods"
|
||||
{:type type
|
||||
:object obj}))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue