ITADN

BSON: case class with Map field that has a key as a wrapped primitive gets serialized as BSONArray

#897Openvvlevykin 创建于 2025-08-12
V
vvlevykincommented
Reproducer with AnyVal in scala 2: https://scastie.scala-lang.org/cXBILsYCSlOGnc6ztQeaqA or neotype: https://scastie.scala-lang.org/0pVBz6NQTDC5V0J3J3DLGA ``` case class ClassWithMap(m: Map[NonEmptyString, Int]) derives Schema ClassWithMap(Map(NonEmptyString("X") -> 10) ``` gets serialized as: ``` {"m": [{"_1": "X", "_2": 10}]} ``` instead of: ``` {"m": {"X": 10}} ``` `BsonSchemaCodec` only handles Schema.Primitive and does not handle Schema.Transform(Schema.Primitive) https://github.com/zio/zio-schema/blob/d2c505c24457378db63b73f1c472c190c2dfde48/zio-schema-bson/src/main/scala/zio/schema/codec/BsonSchemaCodec.scala#L573-L577 https://github.com/zio/zio-schema/blob/d2c505c24457378db63b73f1c472c190c2dfde48/zio-schema-bson/src/main/scala/zio/schema/codec/BsonSchemaCodec.scala#L912-L914
1 条评论