AngelMunoz / Giraffarig

Small Skeleton of a F# Web API with MongoDB and Giraffe
6 stars 0 forks source link

BsonObjectId Automatic JSON Serialization #1

Open felipeotarola opened 3 years ago

felipeotarola commented 3 years ago

Hello.

I'm trying to get this project running, but getting Cannot generate auto decoder for MongoDB.Bson.BsonObjectId When I try to sign up a user.

Have tried different solutions, and even asked in stack overflow. but the problem seems to be that it's expects a valid BsonObjectId from client side.

Thanks for creating this template.

AngelMunoz commented 3 years ago

Hello there this template uses Thoth.Json.Giraffe 4.2.0 so it might be good to look at their docs https://thoth-org.github.io/Thoth.Json/ the idea is that you may need to extend the type to generate a decoder for it you can ask also in https://gitter.im/fable-compiler/Fable to see if they have a quick answer

Also, you can switch to System.Text.Json and https://github.com/Tarmil/FSharp.SystemTextJson like I did here https://github.com/AngelMunoz/PalabratorFs/blob/main/Helpers.fs#L18 following the instructions here https://github.com/Tarmil/FSharp.SystemTextJson/blob/master/docs/Using.md#using-with-giraffe

that way you can do a string <-> ObjectId almost transparent If you find any of the approaches useful consider sending a Pull request and I'll gladly review it

edit: I don't have much time these days otherwise I would do it myself right away