Skip to content

Serialization

Suite framework leverage Newtonsoft.Json features for serializing objects. Serialization takes place mainly at:

  • ASP.NET Core pipeline to deserialize incoming request (json) into proper DTO types.
  • MassTransit when producing / consuming messages, since they must be sent over the wire and re-created in the other side.

Suite framework helps you by auto-discovering and registering your custom serializers properly for ASP.NET Core and MassTransit.

Custom serialization can be done through providing JsonConverter implementations. Suite framework will auto-discover your JsonConverter types, and will pull them into the serializer configuration, either for ASP.NET Core or MassTransit modules.

Important

Be aware of not using System.Text.Json types or features, because the Suite frameworks uses Newtonsoft.Json under the hood for serialization purposes.

ASP.NET Core serialization

Suite framework's Endpoints module configures ASP.NET Core pipeline to use Newtonsoft.Json serializer. Endpoints module will auto-discover and register your JsonConverter types.

If you need to disable JsonSerializer auto-discover feature, you have to tweak EndpointsModuleOptions as follows:

C#
public class TestModule : SuiteAspNetApplicationModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);

        builder.DependsOn<EndpointsModule, EndpointsModuleOptions>(opts =>
        {
            opts.AutoDiscoverJsonConverters = false;
            opts.AddJsonConverter<MyCustomConverter>();
        });
    }
}

MassTransit serialization

Suite framework's MassTransit module auto-discovers your JsonConverter types and registers them into Newtonsoft.Json serializer.

If you need to disable JsonSerializer auto-discover feature, you have to tweak MassTransitModuleOptions as follows:

C#
public class TestModule : SuiteModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);

        builder.DependsOn<MassTransitModule, MassTransitModuleOptions>(opts =>
        {
            opts.AutoDiscoverJsonConverters = false;
            opts.AddConverter<MyCustomConverter>();
        });
    }
}