Skip to content

Commit

Permalink
Add crux.nippy.allow-serializable-classes Java property to add Java c…
Browse files Browse the repository at this point in the history
…lasses to Nippy's post 2.15.0 allow-list
  • Loading branch information
jarohen committed Aug 24, 2020
1 parent 24c96e6 commit bb1d32d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
18 changes: 11 additions & 7 deletions crux-core/src/crux/codec.clj
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
(ns ^:no-doc crux.codec
#:clojure.tools.namespace.repl{:load false, :unload false} ; because of the deftypes in here
(:require [clojure.edn :as edn]
[clojure.string :as str]
[crux.hash :as hash]
[crux.io :as cio]
[crux.memory :as mem]
[crux.morton :as morton]
[taoensso.nippy :as nippy]
[crux.io :as cio]
[clojure.walk :as walk])
(:import [clojure.lang IHashEq Keyword APersistentMap APersistentSet]
[java.io Closeable Writer]
[clojure.set :as set])
(:import [clojure.lang APersistentMap APersistentSet IHashEq Keyword]
java.io.Writer
[java.net MalformedURLException URI URL]
[java.nio ByteOrder ByteBuffer]
[java.nio ByteBuffer ByteOrder]
java.nio.charset.StandardCharsets
[java.util Arrays Collection Date Map UUID Set]
[java.util Date Map Set UUID]
[org.agrona DirectBuffer ExpandableDirectByteBuffer MutableDirectBuffer]
org.agrona.concurrent.UnsafeBuffer))

(set! *unchecked-math* :warn-on-boxed)

;; see https://github.com/ptaoussanis/nippy/issues/130
(when-let [serialisable-classes (System/getProperty "crux.nippy.allow-serializable-classes")]
(nippy/swap-serializable-whitelist! #(set/union % (str/split serialisable-classes #":"))))

;; Indexes

;; NOTE: Must be updated when existing indexes change structure.
Expand Down
13 changes: 12 additions & 1 deletion crux-core/test/crux/codec_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[crux.fixtures :as fix]
[clojure.test.check.clojure-test :as tcct]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop])
[clojure.test.check.properties :as prop]
[crux.api :as crux])
(:import crux.codec.Id
java.util.Date
java.net.URL))
Expand Down Expand Up @@ -120,3 +121,13 @@
:foo {:a 1, :b 2}})
(c/new-id {:crux.db/id :foo
:foo {:b 2, :a 1}})))))

(t/deftest test-java-type-serialisation-1044
(with-open [node (crux/start-node {:crux.node/topology 'crux.standalone/topology})]
(let [doc {:crux.db/id :foo
:date (java.util.Date.)
:uri (java.net.URI. "https://google.com")
:url (java.net.URL. "https://google.com")
:uuid (java.util.UUID/randomUUID)}]
(fix/submit+await-tx node [[:crux.tx/put doc]])
(t/is (= doc (crux/entity (crux/db node) :foo))))))
3 changes: 2 additions & 1 deletion crux-test/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
[org.tukaani/xz "1.8"]
[com.github.spotbugs/spotbugs-annotations "3.1.9"]
[org.eclipse.jetty/jetty-util "9.4.22.v20191022"]
[org.eclipse.jetty/jetty-http "9.4.22.v20191022"]]}}
[org.eclipse.jetty/jetty-http "9.4.22.v20191022"]]
:jvm-opts ["-Dcrux.nippy.allow-serializable-classes=java.net.URL"]}}

:aliases {"test" ["with-profile" "+test" "run" "-m" "circleci.test/dir" :project/test-paths]
"tests" ["with-profile" "+test" "run" "-m" "circleci.test"]
Expand Down
6 changes: 6 additions & 0 deletions dev/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@

(defn crux-node []
(:node system))

#_(crux/submit-tx (crux-node) [[:crux.tx/put {:crux.db/id :foo
:date (java.util.Date.)
:uri (java.net.URI. "https://google.com")
:url (java.net.URL. "https://google.com")
:uuid (java.util.UUID/randomUUID)}]])
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@

:jvm-opts ["-Dlogback.configurationFile=resources/logback-test.xml"
"-Dclojure.spec.compile-asserts=true"
"-Dclojure.spec.check-asserts=true"]
"-Dclojure.spec.check-asserts=true"
"-Dcrux.nippy.allow-serializable-classes=java.net.URL"]
:global-vars {*warn-on-reflection* true}

:aliases {"check" ["sub" "-s" ~(->> modules (remove #{"crux-jdbc"}) (clojure.string/join ":")) "check"]
Expand Down

0 comments on commit bb1d32d

Please sign in to comment.