C#C
C#3y ago
Kiel

❔ System.Text.Json deserializing and serializing polymorphic classes WITHOUT a discriminator

I have a base class (record) and two derived records:
public abstract record LfsResponseObject(
        string Hash,
        long Size);

public record LfsResponseDataObject(
        string Hash,
        long Size,
        IReadOnlyDictionary<string, LfsResponseObjectAction> Actions,
        bool? Authenticated = null) : LfsResponseObject(Hash, Size);

public record LfsResponseErrorObject(
        string Hash,
        long Size,
        LfsObjectError Error) : LfsResponseObject(Hash, Size)


I need to be able to serialize these in a JSON API response, and I cannot utilize discriminators because I am adhering to the git-lfs API spec. Is my only option to create a custom JsonConverter? I don't remember Newtonsoft.Json having these kinds of issues...

Edit. I can't seem to close posts because @Accord is down. I've resolved this issue by going about it a different way.
Was this page helpful?