Skip to content

Proposal: Controller.Json() overloads are confusing in 3.0, expose extensions methods. #12171

Closed
@NickCraver

Description

@NickCraver

In previous versions of ASP.NET Core, the overloads for rendering Json were:

public virtual JsonResult Json(object data, JsonSerializerSettings serializerSettings);
public virtual JsonResult Json(object data);

Here, JsonSerializerSettings is Newtonsoft.Json.JsonSerializerSettings.

Since decoupling the dependency in 3.0 though, it's now:

public virtual JsonResult Json(object data, object serializerSettings);
public virtual JsonResult Json(object data);

While this makes sense to decouple from Newtonsoft specifically, it makes for a poor user experience. For example, I couldn't readily find what type I'm supposed to be using for the serializerSettings argument.

Is there harm in adding additional overloads that are specific? For example, the Microsoft.AspNetCore.Mvc.NewtonsoftJson package could add a:

public static Json(this Controller controller, object data, JsonSerializerSettings serializerSettings);

It'd expose a specific overload for the user to use. The same for System.Text.Json.

If all of this isn't doable for API compat reasons, at the very least the docs should be updated. The out-of-the-box experience with System.Text.Json is very confusing and leaves a user lost on what they're supposed to be doing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions