Zaid-Ajaj / LiteDB.FSharp

Advanced F# Support for LiteDB, an embedded NoSql database for .NET with type-safe query expression through F# quotations
MIT License
180 stars 22 forks source link

FSharpBsonMapper ignoring custom type registrations #42

Closed BennieCopeland closed 3 years ago

BennieCopeland commented 4 years ago

I'm using NodaTime LocalDate types on my records that I want to serialize as strings and deserialize back to LocalDates . The FSharpBsonMapper is ignoring the custom type mappings.

BennieCopeland commented 4 years ago

After code splunking, I was able to work around the issue with a custom JsonConverter like so:

FSharpBsonMapper.UseCustomJsonConverters(new JsonConverter[] {new LocalDateJsonConverter(), new FSharpJsonConverter()});
Zaid-Ajaj commented 4 years ago

Hello there @BennieCopeland, I am glad you were able to find the workaround! Do we need to add something from library point of view? (Maybe some docs I would guess)

BennieCopeland commented 4 years ago

Hi @Zaid-Ajaj, docs would be nice, yes. From a library point of view, maybe not make the converters global. I could see it potentially being useful to have different converters/mappers for different LiteDatabase files. And either always include the FSharpJsonConverter and provide a second method to replace it, or document that the developer has to provide it along with their custom converters. I'm a fan of the former, as that converter is the core of the record/DU/tuple handling, and I expect will rarely need to be overridden.