Simplify.Web.Json

Simplify.Web JSON controller response and model binder


Keywords
JSON, Simplify.Web, dot-net, dot-net-core, simplify, simplify-web
License
LGPL-3.0
Install
Install-Package Simplify.Web.Json -Version 1.3.0

Documentation

Simplify.Web.Json

Nuget Version Nuget Download Build PackageLibraries.io dependency status for latest release CodeFactor Grade Platform PRs Welcome

Simplify.Web.Json is a package which provides JSON serialization/deserialization for Simplify.Web web-framework controllers.

Quick Start

Sending JSON to client

If the controller returns Json response class object, then the Framework execution will be stopped, object will be parsed to JSON string and sent to client

public class MyController : Controller
{
    public override ControllerResponse Invoke()
    {
        ...
        return new Json(myObj);
    }
}

Getting JSON from client

Registering binder

public void Configuration(IApplicationBuilder app)
{
    ...
    HttpModelHandler.RegisterModelBinder<JsonModelBinder>();

    app.UseSimplifyWeb();
}

public void ConfigureServices(IServiceCollection services)
{
    ...
    DIContainer.Current.RegisterJsonModelBinder();
    ...
}

Accessing model

Asynchronous
public class MyController : ControllerAsync<MyModel>
{
    public override async Task<ControllerResponse> Invoke()
    {
        await ReadModelAsync();

        Model.
    }
}
Synchronous

JSON string will be deserialized to the controller model on first model access

public class MyController : Controller<MyModel>
{
    public override ControllerResponse Invoke()
    {
        Model.
    }
}