Helper methods for working with Microsoft.AspNetCore.Mvc.ProblemDetails responses.
Remarks: This class provides utilities for detecting, parsing, and extracting information from ProblemDetails JSON. ProblemDetails is a standardized format (RFC 7807) for returning error information from HTTP APIs.
public static class ProblemDetailsHelper
bool IsFormatJsonAndProblemDetailsModel(string value)Summary: Determines whether the specified string is a JSON-formatted ProblemDetails model containing at least one of the expected top-level properties (
status,title,detail) — the comparison is case-insensitive on property names so it tolerates both PascalCase and camelCase serialization styles.Parameters:
value- The string to check.Returns: if the value is valid JSON whose root object exposes any of the ProblemDetails properties; otherwise, .
bool TrySerializeToProblemDetails(string value, out ProblemDetails problemDetails)Summary: Attempts to deserialize a JSON string to a
Microsoft.AspNetCore.Mvc.ProblemDetailsobject.Parameters:
value- The JSON string to deserialize.
problemDetails- When this method returns, contains the deserialized ProblemDetails if successful; otherwise, null.Returns: True if deserialization succeeded; otherwise, false.
bool TrySerializeToProblemDetailsAndGetDetails(string value, out string detailValue)Summary: Attempts to deserialize a JSON string to ProblemDetails and extract the detail message.
Parameters:
value- The JSON string to deserialize.
detailValue- When this method returns, contains the detail message if successful; otherwise, null.Returns: True if deserialization succeeded; otherwise, false.
bool TrySerializeToProblemDetailsAndGetStatusCode(string value, out HttpStatusCode? statusCodeValue)Summary: Attempts to deserialize a JSON string to ProblemDetails and extract the HTTP status code.
Parameters:
value- The JSON string to deserialize.
statusCodeValue- When this method returns, contains the HTTP status code if successful; otherwise, null.Returns: True if deserialization succeeded and status code was extracted; otherwise, false.
bool TrySerializeToProblemDetailsAndGetTitle(string value, out string titleValue)Summary: Attempts to deserialize a JSON string to ProblemDetails and extract the title.
Parameters:
value- The JSON string to deserialize.
titleValue- When this method returns, contains the title if successful; otherwise, null.Returns: True if deserialization succeeded; otherwise, false.