-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
207 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
zio-schema-bson/src/main/scala/zio/schema/codec/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package zio.schema.codec | ||
|
||
import org.bson.types.ObjectId | ||
|
||
import zio.schema.{ Schema, TypeId } | ||
|
||
package object bson { | ||
val ObjectIdTag = "$oid" | ||
|
||
implicit val ObjectIdSchema: Schema[ObjectId] = | ||
Schema.CaseClass1[String, ObjectId]( | ||
id0 = TypeId.fromTypeName("ObjectId"), | ||
field0 = Schema.Field( | ||
name0 = ObjectIdTag, | ||
schema0 = Schema[String], | ||
get0 = _.toHexString, | ||
set0 = (_, idStr) => new ObjectId(idStr) | ||
), | ||
defaultConstruct0 = new ObjectId(_) | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters