Simplify.Web.Json
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.
}
}