Search code examples
jsonmongodbcasbahsalat

Single serialization layer to Json with Casbah/Salat


I am trying to create a serialization layer which allows me to:

  • Store my classes in a MongoDB data source
  • Convert them to JSON to use them in a REST API.

Some classes are clearly not case classes (because they are inherited from a Java codebase) and I would have to write ad-hoc code for that. Is registering a BSON Hook for my non standard type the correct approach, and does it provide Json serialization?


Solution

  • Salat maintainer here.

    You might prefer to create a Salat custom transformer instead of registering a BSON hook with Casbah.

    See simple example and spec.

    If you run into any issues, feel free to ping the mailing list with a small sample Github project that demonstrates what isn't working.