spray/spray-json

val instead of object for BigInt and BigDecimal

fommil opened this issue · 0 comments

I would like to use a custom marshaller for BigInt and BigDecimal, to use JsString instead of JsNumber.

The reason for this is because we are re-using Spray JSON marshallers to serialise to/from MongoDB objects. Despite claims that BSON is a superset of JSON, it doesn't support arbitrary precision numbers. i.e. there is no such thing as BsonNumber – it's all ints or longs, floats or doubles. The workaround is that any arbitrary precision numbers must be serialised as String in MongoDB.

Unfortunately, because the implicit JsonFormats are defined as implicit object, the scala compiler will not let me override them. If they were implicit val, I believe this would be ok.