diff --git a/src/monger/convertion.clj b/src/monger/convertion.clj index 85ce74c..42fad7b 100644 --- a/src/monger/convertion.clj +++ b/src/monger/convertion.clj @@ -50,6 +50,10 @@ (from-db-object [#^List input keywordize] (vec (map #(from-db-object % keywordize) input))) + BasicDBList + (from-db-object [#^BasicDBList input keywordize] + (vec (map #(from-db-object % keywordize) input))) + DBObject (from-db-object [#^DBObject input keywordize] ;; DBObject provides .toMap, but the implementation in diff --git a/test/monger/test/convertion.clj b/test/monger/test/convertion.clj index 035f506..5a3b849 100644 --- a/test/monger/test/convertion.clj +++ b/test/monger/test/convertion.clj @@ -94,10 +94,15 @@ (deftest convert-flat-db-object-to-nested-map (let [did "b38b357f5014a3250d813a16376ca2ff4837e8e1" - nested (doto (BasicDBObject.) (.put "int" 101) (.put "dblist" (doto (BasicDBList.) (.put "0" 0) (.put "1" 1))) (.put "list" (ArrayList. ["red" "green" "blue"])) (.put "nil" nil)) + nested (doto (BasicDBObject.) + (.put "int" 101) + (.put "dblist" (doto (BasicDBList.) (.put "0" 0) (.put "1" 1))) (.put "list" (ArrayList. ["red" "green" "blue"]))) input (doto (BasicDBObject.) (.put "_id" did) - (.put "nested" nested))] - (is (= (monger.convertion/from-db-object input false) { "_id" did, "nested" { "int" 101, "dblist" {"0" 0, "1" 1}, "list" ["red" "green" "blue"], "nil" nil } })) - (is (= (monger.convertion/from-db-object input true) { :_id did, :nested { :int 101, :dblist {:0 0, :1 1}, :list ["red" "green" "blue"], :nil nil } })) - )) + (.put "nested" nested)) + output (monger.convertion/from-db-object input false)] + (is (= (output "_id") did)) + (is (= (-> output (get "nested") (get "int")) 101)) + (is (= (-> output (get "nested") (get "list")) ["red" "green" "blue"])) + (is (= (-> output (get "nested") (get "dblist")) [0 1])))) +