public
Created

java.lang.IllegalArgumentException: can't serialize class scala.math.BigDecimal

  • Download Gist
TestLoadingJsNumber.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package test
 
import com.mongodb.casbah.Imports._
import org.scalatest._
import org.scalatest.matchers.ShouldMatchers
import play.api.libs.json._
import play.api.{Play, Logger}
 
class TestLoadingJsNumber extends FlatSpec with ShouldMatchers {
 
"Trying to Insert a JsNumber" should "throw a BSON exception when trying BigDecimal serialization" in {
val collection = MongoConnection()("test")("test")
val obj: JsValue = Json.obj("age" -> JsNumber(100))
 
println("Json.stringify(obj): " + Json.stringify(obj))
 
val q = MongoDBObject("name" -> obj)
collection.insert(q)
}
}

Note that replacing val obj... with the below line also throws a BSON serialization exception.

val obj: JsValue = Json.obj("age" -> 100)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.