Transforming own type into ProblemDetails

So, I really like using application/problem+json to specify my results and for that I have my own ProblemResponse<T> type
public class ProblemResponse<T>
{
public required string Type { get; init; }
public required int Status { get; init; }
public required string Title { get; init; }
public required string Detail { get; init; }
public required string UriPath { get; init; }
public required string Method { get; init; }
public required T? Extensions { get; init; }
}
public class ProblemResponse<T>
{
public required string Type { get; init; }
public required int Status { get; init; }
public required string Title { get; init; }
public required string Detail { get; init; }
public required string UriPath { get; init; }
public required string Method { get; init; }
public required T? Extensions { get; init; }
}
Which has all the specification fields + extensions The thing is that dotnet's ProblemDetails type is not generic in any way, it uses a dictionary. The type could be shortened to this
public class ProblemDetails {
public string? Type { get; set; }
public string? Title { get; set; }
public int? Status { get; set; }
public string? Detail { get; set; }
public string? Instance { get; set; }
[JsonExtensionData]
public IDictionary<string, object?> Extensions { get; set; }
}
public class ProblemDetails {
public string? Type { get; set; }
public string? Title { get; set; }
public int? Status { get; set; }
public string? Detail { get; set; }
public string? Instance { get; set; }
[JsonExtensionData]
public IDictionary<string, object?> Extensions { get; set; }
}
Is there any ways to transform from my type to theirs? or do I just use my type and not use the application/problem+json header? sry for the long text
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server