Skip to content

Ability to configure custom JSON.parse reviver for the HttpClient #21079

@bygrace1986

Description

@bygrace1986

I'm submitting a...


[x] Feature request

Current behavior

With the new HttpClient if the responseType is set to 'json' or if it is not set (defaulted to 'json') then the JSON is parsed before being returned to the consuming code. Here is the source-code where the JSON.parse occurs:

body = body !== '' ? JSON.parse(body) : null;

Expected behavior

A reviver function can be configured that the HttpClient will use when parsing json. As far as the implementation, maybe an injection token can be exposed which developers can use to provide a reviver function.

What is the motivation / use case for changing the behavior?

Dates are deserialized as strings with JSON.parse. It is convenient to have dates serialized to Date objects globally via a centralized service using a reviver.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions