ITADN

`toBsonValue` for a fallback schema serializes to a BSONArray

#898Openvvlevykin 创建于 2025-08-13
V
vvlevykincommented
Reproducer: https://scastie.scala-lang.org/qJaft9v0QPmIiZglkWYYHQ ``` case class ClassWithInt(intField: Int) derives Schema case class ClassWithString(strField: String) given Schema[ClassWithString] = DeriveSchema.gen[ClassWithString].orElse( Schema[ClassWithInt].transform( a => ClassWithString(a.intField.toString), a => ClassWithInt(a.strField.toInt) ) ) ClassWithString("X") // => [{"strField": "X"}] ``` I'm not sure if I'm using fallback here correctly but it seems that `fromBsonValue`, `encode` and `decode` work as expected. I suspect that the problem may be here: https://github.com/zio/zio-schema/blob/d2c505c24457378db63b73f1c472c190c2dfde48/zio-schema-bson/src/main/scala/zio/schema/codec/BsonSchemaCodec.scala#L429-L430
0 条评论