I have a record with an additional convenience constructor:
public record PublishedTestMethod(Guid Id, string Name, int Version, string Status, Guid? Publisher,
DateTimeOffset? DatePublished)
{
public PublishedTestMethod(TestMethod tm) : this(tm.Id, tm.Name, tm.Version, tm.Status, tm.Publisher,
tm.DatePublished)
{
}
}
I would like to deserialize this from a JSON object:
JsonConvert.DeserializeObject<PublishedTestMethod>(json);
I get the error:
Unable to find a constructor to use for type Namespace.PublishedTestMethod. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute.
Ideally, I'd like to assign the [JsonConstructor] attribute to the long constructor, as I think this would let it map nicely from the JSON. Adding it to the record itself doesn't work, and I can't see an attribute target for a constructor. Is there a way to do this?