5.32Response JSON Double Serialization Handling
When communicating remotely with third-party APIs over HTTP, in very rare cases the JSON data returned by the server may be unintentionally double-serialized (sometimes deliberately). For example, instead of returning "{\"id\":1,\"name\":\"furion\"}", double serialization turns it into "\"{\\\"id\\\":10, \\\"name\\\":\\\"furion\\\"}\"". For such cases, the framework provides unwrapping support.
HTTP declarative requests enable unwrapping of the JSON response content string through the JsonResponseStringUnwrapAttribute attribute. The corresponding HTTP declarative extractor implementation is the JsonResponseStringUnwrapDeclarativeExtractor type, which is responsible for parsing the JsonResponseStringUnwrapAttribute attribute and building the configuration required by the HttpRequestBuilder instance to enable unwrapping of the JSON response content string.
// Applied at the interface definition, affecting all methods[JsonResponseStringUnwrap]public interface IHttpService : IHttpDeclarative{ // Applied automatically by default [Get("https://furion.net/")] Task<YourModel> GetAsync(); // Applied at the method level [JsonResponseStringUnwrap] // Can be explicitly enabled (not required) [Get("https://furion.net/")] Task<YourModel> GetAsync(); [JsonResponseStringUnwrap(false)] // Disable unwrapping of the JSON response content string [Get("https://furion.net/")] Task<YourModel>> GetAsync();}If you need to disable this feature for a specific request, set the [JsonResponseStringUnwrap(false)] attribute.
JsonResponseStringUnwrapAttribute contains the following constructors and properties:
-
Constructors:
new(): Applies to methods or interfaces, enabling unwrapping of theJSONresponse content string.new(enabled): Applies to methods or interfaces, setting whether unwrapping of theJSONresponse content string is enabled.
-
Properties:
Enabled: Whether it is enabled (booltype), defaulting totrue(enabled).