Skip to content

Commit

Permalink
Serialize lists of any type, not just embedded documents. Fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
zbjornson committed Jan 11, 2016
1 parent 6fdce0a commit 41b0a06
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
14 changes: 7 additions & 7 deletions MongoDBLink.m
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,6 @@
newdbobj
]

serialize[_, x : { $rulepattern }] := Block[
{newdblist = JavaNew["com.mongodb.BasicDBList"]},
MapIndexed[newdblist@put[First[#2] - 1, serialize[#]]&, x];
newdblist
]

(* $in, $nin, ... *)
serialize[dbobj_, Rule["_id", {a_ -> b_}]] :=
dbobj@put["_id", serialize[dbobj, {a -> (ObjectId /@ b)}]]
Expand All @@ -304,7 +298,13 @@

serialize[dbobj_, {}] := JavaNew["com.mongodb.BasicDBObject"]

serialize[dbobj_, x_] := MakeJavaObject[x] (*:(_Integer|_Real|_String|_List|True|False)*)
serialize[dbobj_, x_List] := Block[
{newdblist = JavaNew["com.mongodb.BasicDBList"]},
MapIndexed[newdblist@put[First[#2] - 1, serialize[Null, #]]&, x];
newdblist
]

serialize[dbobj_, x_] := MakeJavaObject[x] (*:(_Integer|_Real|_String|True|False)*)

serialize[dbobj_, x_?JavaObjectQ] := x

Expand Down
2 changes: 1 addition & 1 deletion PacletInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Paclet[
Name -> "MongoDBLink",
Version -> "0.1.2",
Version -> "0.1.3",
MathematicaVersion -> "6+",
Extensions ->
{
Expand Down
8 changes: 8 additions & 0 deletions Tests.wlt
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ VerificationTest[
TestID->"aa43675c-c925-4450-b221-8cb964194447"
]

VerificationTest[
MongoDBLink`Private`serialize[Null, {"a", 1}]@toString[]
,
"[ \"a\" , 1]"
,
TestID->"fb9e1587-20db-49d5-a67e-c9b04d7a35a4"
]

EndTestSection[]

VerificationTest[
Expand Down

0 comments on commit 41b0a06

Please sign in to comment.