File tree Expand file tree Collapse file tree
src/FSharp.MongoDB.Bson/Serialization/Serializers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ open MongoDB.Bson.Serialization.Serializers
2626type FSharpOptionSerializer < 'T when 'T: not null >() =
2727 inherit SerializerBase< 'T option>()
2828
29- let serializer = lazy ( BsonSerializer.LookupSerializer< 'T>())
29+ let serializer : Lazy < IBsonSerializer < 'T >> =
30+ lazy ( BsonSerializer.LookupSerializer< 'T>())
3031
3132 override _.Serialize ( context , args , value ) =
3233 let writer = context.Writer
@@ -40,4 +41,6 @@ type FSharpOptionSerializer<'T when 'T: not null>() =
4041
4142 match reader.GetCurrentBsonType() with
4243 | BsonType.Null -> reader.ReadNull(); None
43- | t -> Some ( serializer.Value.Deserialize( context, args))
44+ | _ ->
45+ // Use the inner serializer's nominal type to avoid recursing through the option serializer.
46+ Some ( serializer.Value.Deserialize( context))
Original file line number Diff line number Diff line change @@ -26,18 +26,23 @@ open MongoDB.Bson.Serialization.Serializers
2626type FSharpValueOptionSerializer < 'T when 'T: not null >() =
2727 inherit SerializerBase< 'T voption>()
2828
29- let serializer = lazy ( BsonSerializer.LookupSerializer< 'T>())
29+ let serializer : Lazy < IBsonSerializer < 'T >> =
30+ lazy ( BsonSerializer.LookupSerializer< 'T>())
3031
3132 override _.Serialize ( context , args , value ) =
3233 let writer = context.Writer
3334
3435 match value with
35- | ValueSome x -> serializer.Value.Serialize( context, args, x :> obj)
36+ | ValueSome x ->
37+ // Serialize using the inner serializer's nominal type.
38+ serializer.Value.Serialize( context, x)
3639 | ValueNone -> writer.WriteNull()
3740
3841 override _.Deserialize ( context , args ) =
3942 let reader = context.Reader
4043
4144 match reader.GetCurrentBsonType() with
4245 | BsonType.Null -> reader.ReadNull(); ValueNone
43- | _ -> ValueSome ( serializer.Value.Deserialize( context, args))
46+ | _ ->
47+ // Use the inner serializer's nominal type to avoid recursing through the option serializer.
48+ ValueSome ( serializer.Value.Deserialize( context))
You can’t perform that action at this time.
0 commit comments