5

The scala-mongo-driver has a decent documentation for working with case classes. http://mongodb.github.io/mongo-scala-driver/2.3/getting-started/quick-tour-case-classes/. In current situation my case class fields are Option[T] values. So the values can be either None or Some(T).The default codec is now serializing 'None' values as null. But I want to exclude the key if its value is None. How can I obtain this behavior? From my research I think we need to write a custom Codec or Codec Provider for the case class instead of the default case class codec.

Ambareesh B
  • 499
  • 1
  • 5
  • 14

1 Answers1

2

There is an new macro helper since v2.1.0: Macros.createCodecProviderIgnoreNone where you can define that None values will be ignored from saving to the DB.

Ghashange
  • 1,027
  • 1
  • 10
  • 20