I have implemented the port, using zio-bson version 1.0.6, (compatible with 3.3.x), 1.0.7 and 1.0.8 are only compatible with 3.4.x and 3.5.x respectively. zio-bson does the most of heavy lifting.
Implemented ObjectId - Since we dont have TypeId, it checks for typename ObjectId in namespace org.bson.type. The ObjectId is represented as a wrapper around String (hex representation), but when encoded to BSON, it uses the native BsonType.OBJECT_ID (12-byte format) via special handling in BsonSchemaCodec.
zio-bson comes with it own annotation, in old implementation they have priority over zio schema annotation, I have replicated the said annotations, using either Modifier or Config.
zio-bson annotations, at bson/annotation.scala are Scala annotations classes, and Not Modifer instances. Term and Reflect types only store, Modifer.Term and Modifer.Reflect, they do not preserve raw scala annotation. (Fairly certain of this)
I tried doing case class bsonField(name: String) extends Modifier.Term, but both of those are sealed traits and cannot be extended outside of their source files. I can use Modifer.config for BSON specific behavior
case class User(
@Modifier.config("bson.field", "bson_name")
@Modifier.rename("json_name")
field: String
)
But it is a very verbose syntax and is not comptable with old @bsonField annotation. This means there are not tests for the annotations and no tests for mixed config priority of annotation testing. I am unsure how to handle this or what the expectation here is.
The current implementation -
| Feature | Old Schema Annotation | BSON Annotation | Current zio-blocks |
|---|---|---|---|
| Field rename | @fieldName("x") |
@bsonField("y") |
Modifier.rename("y") |
| Case rename | @caseName("x") |
@bsonHint("y") |
Modifier.rename("y") |
| Transient field/case | @transientField / @transientCase |
@bsonExclude |
Modifier.transient() |
| Reject extra fields | @rejectExtraFields |
@bsonNoExtraFields |
Config.withIgnoreExtraFields(false) |
| Discriminator name | @discriminatorName("x") |
@bsonDiscriminator("y") |
Config.withSumTypeHandling(DiscriminatorField("y")) |
/claim #683 /closes #683
Ajay RV
@Nanashi-lab
ZIO
@ZIO