serde
serde copied to clipboard
Friction connecting serializers to ISerialize<T>
Hello and thank you for this great library. I have a prototype Cbor Serializer that is built on Serde and I've been trying to keep up with the new API changes.
I'm trying to understand the idiomatic way to use a custom serializer.
[GenerateSerialize, GenerateDeserialize]
public record Foo(...);
public class CborSerializer : ISerializer { ... }
void Main()
{
var foo = new Foo();
var serializer = new CborSerializer(...);
//...?
}
The tension is on how I'm supposed to pass foo
to the serializer. The source generator for Foo uses an explicit interface implementation for the Serialize method, which forces me to cast it to use it directly. But if foo is a struct then i actually need to use a guarded generic call, which leads me towards an extension method for ISerializer
or a method directly on CborSerializer
class.
But that class has a bunch of interface methods that are supposed to be implementation details. Looking at the included JsonSerializer, it hides these methods by making them explicit implementations also. Is this the expected pattern? It kinda feels like there should be an in-box way of linking these two concepts.