Refactor reading of possibly-unthawable types
This commit is contained in:
parent
53714cc192
commit
2b19f8eab5
1 changed files with 31 additions and 25 deletions
|
|
@ -490,21 +490,40 @@
|
||||||
|
|
||||||
id-reader
|
id-reader
|
||||||
(let [edn (read-utf8 in)]
|
(let [edn (read-utf8 in)]
|
||||||
(try (edn/read-string {:readers *data-readers*} edn)
|
(try
|
||||||
(catch Exception e {:nippy/unthawable edn
|
(edn/read-string {:readers *data-readers*} edn)
|
||||||
:type :reader
|
(catch Exception e
|
||||||
:throwable e})))
|
{:type :reader
|
||||||
|
:throwable e
|
||||||
|
:nippy/unthawable edn})))
|
||||||
|
|
||||||
id-serializable
|
id-serializable
|
||||||
(let [class-name (read-utf8 in)]
|
(let [class-name (read-utf8 in)]
|
||||||
(try (let [;; .readObject _before_ Class/forName: it'll always read
|
(try
|
||||||
;; all data before throwing
|
(let [content (.readObject (ObjectInputStream. in))]
|
||||||
object (.readObject (ObjectInputStream. in))
|
(try
|
||||||
^Class class (Class/forName class-name)]
|
(let [class (Class/forName class-name)]
|
||||||
(cast class object))
|
(cast class content))
|
||||||
(catch Exception e {:nippy/unthawable class-name
|
(catch Exception e
|
||||||
:type :serializable
|
{:type :serializable
|
||||||
:throwable e})))
|
:throwable e
|
||||||
|
:nippy/unthawable {:class-name class-name :content content}})))
|
||||||
|
(catch Exception e
|
||||||
|
{:type :serializable
|
||||||
|
:throwable e
|
||||||
|
:nippy/unthawable {:class-name class-name :content nil}})))
|
||||||
|
|
||||||
|
id-record
|
||||||
|
(let [class-name (read-utf8 in)
|
||||||
|
content (thaw-from-in in)]
|
||||||
|
(try
|
||||||
|
(let [class (Class/forName class-name)
|
||||||
|
method (.getMethod class "create" class-method-sig)]
|
||||||
|
(.invoke method class (into-array Object [content])))
|
||||||
|
(catch Exception e
|
||||||
|
{:type :record
|
||||||
|
:throwable e
|
||||||
|
:nippy/unthawable {:class-name class-name :content content}})))
|
||||||
|
|
||||||
id-bytes (read-bytes in)
|
id-bytes (read-bytes in)
|
||||||
id-nil nil
|
id-nil nil
|
||||||
|
|
@ -553,19 +572,6 @@
|
||||||
id-ratio (/ (bigint (read-biginteger in))
|
id-ratio (/ (bigint (read-biginteger in))
|
||||||
(bigint (read-biginteger in)))
|
(bigint (read-biginteger in)))
|
||||||
|
|
||||||
id-record
|
|
||||||
(let [class-name (read-utf8 in)
|
|
||||||
content (thaw-from-in in)]
|
|
||||||
(try
|
|
||||||
(let [class (Class/forName class-name)
|
|
||||||
method (.getMethod class "create" class-method-sig)]
|
|
||||||
(.invoke method class (into-array Object [content])))
|
|
||||||
(catch Exception e
|
|
||||||
{:nippy/unthawable class-name
|
|
||||||
:type :record
|
|
||||||
:content content
|
|
||||||
:throwable e})))
|
|
||||||
|
|
||||||
id-date (Date. (.readLong in))
|
id-date (Date. (.readLong in))
|
||||||
id-uuid (UUID. (.readLong in) (.readLong in))
|
id-uuid (UUID. (.readLong in) (.readLong in))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue