Skip to content

Research-Institute/dotnet-rest-serializer

Repository files navigation

dotnet-rest-serializer

A serializer to make dotnet work with Ember RESTAdapater

Build status

About

For more information including usage, see the blog post

Installation

Install-Package dotnet-rest-serializer

Class Names

services.AddMvc(options =>
{
    options.InputFormatters.Insert(0, new RootNameInputFormatter(o =>
    {
        o.UseClassNames(myAssembly);
    }));
    options.OutputFormatters.Insert(0, new RootNameOutputFormatter(o =>
    {
        o.UseClassNames();
    }));
});

Attribute Definitions

Class definition MUST be in the same assembly as the web project.

// Startup.cs
services.AddMvc(options =>
{
    options.InputFormatters.Insert(0, new RootNameInputFormatter(o =>
    {
        o.UseAttributeDefinition();
    }));
    options.OutputFormatters.Insert(0, new RootNameOutputFormatter(o =>
    {
        o.UseAttributeDefinition();
    }));
});

// TestClass.cs
[SerializationFormat("testClass", "testClasses")]
public class TestClassPresenter
{
    public string Name { get; set; }
}

Dictionary Definitions

var serializationDefinitions = new Dictionary<Type, string> 
{ 
    { typeof(TestClass), "testClass" },
    { typeof(List<TestClass>), "testClasses" }
}; 
services.AddMvc(options => 
{ 
    options.InputFormatters.Insert(0, new RootNameInputFormatter(o =>
    {
        o.UseExplicitDefinition(serializationDefinitions);
    }));
    options.OutputFormatters.Insert(0, new RootNameOutputFormatter(o =>
    {
        o.UseExplicitDefinition(serializationDefinitions);
    }));
}); 

About

A serializer to make dotnet work with Ember RESTAdapater

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published