Zaid-Ajaj / Fable.Remoting

Type-safe communication layer (RPC-style) for F# featuring Fable and .NET Apps
https://zaid-ajaj.github.io/Fable.Remoting/
MIT License
272 stars 54 forks source link

Allow configuring custom json serializer #232

Closed dnperfors closed 3 years ago

dnperfors commented 3 years ago

In a project I am working on, I already have configured a json serializer for serializing custom types to json for storage. I would like to use the same serializer, or at least the JSON Converters to serialize my custom types on the server site of Fable.Remoting as well. I didn't find any way to configure this. Is it something that could be added?

Zaid-Ajaj commented 3 years ago

Hi @dnperfors, if I understand correctly you want to your own serializers inside of Fable.Remoting to handle the JSON conversions. Currently there isn't a way to customize the JSON handling because the clients of Fable.Remoting expect the server to use the built-in serializer and not some custom one, otherwise things will randomly break.

Is it something that could be added?

There aren't any plans to add this possibility because making the JSON converters configurable will open up a whole can of worms of serialization bugs. Things work right now out of the box because the client and server know what to expect

dnperfors commented 3 years ago

@Zaid-Ajaj, I understand your positions.

I had some problems with handling some custom date / time types, but it looks like that was mostly on my side... Besides that, I need to remember that I don't use Fable.Remoting for REST API's, where I expect certain formattin :wink:

hesxenon commented 1 year ago

sorry for hijacking this issue @Zaid-Ajaj I'm just curious as to what kind of serialization bugs you expect?

Currently - as far as I can see - there is no way to serialize a DU which puts a considerable damper on API design. Allowing the usage of a custom serializer/deserializer pair would put the responsibility for this on the users side, no?

I get the whole "batteries included" appeal but why not just say "you can use your own batteries but don't blame me if your system blows up"?

Zaid-Ajaj commented 1 year ago

Hi @hesxenon can you please elaborate on "there is no way to a serialize a DU"? Because in fact, you can serialize very complex ones

hesxenon commented 1 year ago

that's interesting then... I'm trying to create a Nodejs Server implementation (wrote you on gitter) and I can't seem to deserialize them correctly.

I did see that my DU is serialized, but how would it be deserialized correctly if the server impl doesn't know about the DU?

On Mon, Jan 23, 2023, 17:56 Zaid Ajaj @.***> wrote:

Hi @hesxenon https://github.com/hesxenon can you please elaborate on "there is no way to a serialize a DU"? Because in fact, you can serialize very complex ones

— Reply to this email directly, view it on GitHub https://github.com/Zaid-Ajaj/Fable.Remoting/issues/232#issuecomment-1400669060, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACOHZTXL3NPW2R7JLW2OMTLWT2Z2RANCNFSM4ZWZ3SSA . You are receiving this because you were mentioned.Message ID: @.***>

Zaid-Ajaj commented 1 year ago

I am not on gitter these days but usually here, on Twitter and the fsharp slack. You should be able to serialize and deserialize DUs from a nodejs using Fable.SimpleJson which what Fable.Remoting.Client uses

If you have a concrete example that doesn't work, please file an issue