First off thanks for all your hard work in getting the SNAPSHOT out for scala 2.10. While testing, I ran into an issue converting a nested structure to DBObject. Find below a simple snippet that would reproduce the problem (this used to work in casbah 2.9.2_2.4.1)
val m = Map("a" -> 1, "b" -> 2, "c" -> List(Map("x" -> 1), Map("y" -> 2)))
val dbo = MongoDBObject(m.toList)
println(dbo)
Exception in thread "main" java.lang.RuntimeException: json can't serialize type : class scala.Tuple2
at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:77)
at com.mongodb.util.JSONSerializers$IterableSerializer.serialize(JSONSerializers.java:280)
at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79)
at com.mongodb.util.JSONSerializers$IterableSerializer.serialize(JSONSerializers.java:280)
at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79)
at com.mongodb.util.JSONSerializers$MapSerializer.serialize(JSONSerializers.java:307)
at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79)
at com.mongodb.util.JSON.serialize(JSON.java:56)
at com.mongodb.util.JSON.serialize(JSON.java:41)
at com.mongodb.BasicDBObject.toString(BasicDBObject.java:83)
at java.lang.String.valueOf(String.java:2826)
at java.io.PrintStream.println(PrintStream.java:771)
at scala.Console$.println(Console.scala:240)
at scala.Predef$.println(Predef.scala:287)
at persist.PersistTest$.main(PersistTest.scala:56)
at persist.PersistTest.main(PersistTest.scala)
Note: Nested lists and maps work fine. I run into this issue only with nested list that have nested maps.
For Example:
val m2 = Map("a" -> 1, "b" -> List(1, 2)) //... Works
val m3 = Map("a" -> 1, "b" -> Map("bb" -> 1, "cc" -> 2)) //... Works
Thanks,
Arun
Thanks for the reply - seems theres some difference between:
scalaj.collection.Imports._ and scala.collection.JavaConverters._
I'll let you know when I have a fix for that.
Regards,
Ross
This is now fixed and I've pushed a new snapshot.
Seems we have to be more explicit with the transformations under scala.collection.JavaConverters as you could get caught in an infinite loop - commit url: https://github.com/mongodb/casbah/commit/152b60cd844e0e2a290e6d9fc81304fa8123e620#diff-1
Ross
I tested your fix and nested collections are getting transformed as expected.
Thanks for quick turnaround.
Regards,
Arun