eigengo / scalad

Scala Data access for NoSQL databases
47 stars 15 forks source link

Evil Hack™ for BSON Date and UUID formats #45

Closed fommil closed 11 years ago

fommil commented 11 years ago

If we had really fast checkers (e.g. able to work off a fixed character length, and not clashing with many other domain strings), we could potentially detect when a JSON JsString were actually holding a UUID or ISO Date.

This could allow us to have String based JSON marshalling, with optimal BSON serialisation.

Would have to be off by default... it is Evil™ afterall.

fommil commented 11 years ago

@janm399 ? WhatThinkYou()

fommil commented 11 years ago

Instructions to enable

https://gist.github.com/1388063c7d87e9e0d839

janm399 commented 11 years ago

I can see where the evil lies. I hope some good pattern will emerge with #47

fommil commented 11 years ago

@janm399 the evilness is definitely that we're inspecting the Strings – certainly I can clean up the pattern matcher by using Regexes, but I can't see a way around the fact that we're still inspecting Strings (or JsNumber in the case of BigDecimal).

fommil commented 11 years ago

@janm399 an alternative to the current form of inspection, of course, is that we have more complex JSON, e.g. instead of

{ "key": "2013-02-05T10:38:10+0000"}

we could follow the Mongo JSON syntax format and marshall to this

{ "key" : { "$date" : "2013-02-05T10:38:10.000Z"}}

(note milliseconds)

Anytime we ever see one of the magic $markers, we could invoke the correct serialiser. This might be a nice pattern, because it means we would implement a read/write/serialise/deserialise all in one place – the Spray JSON JsonFormat.

The downside of this approach is that the JSON endpoints will see this domain language.