A serializer to make dotnet work with Ember RESTAdapater
For more information including usage, see the blog post
Install-Package dotnet-rest-serializer
services.AddMvc(options =>
{
options.InputFormatters.Insert(0, new RootNameInputFormatter(o =>
{
o.UseClassNames(myAssembly);
}));
options.OutputFormatters.Insert(0, new RootNameOutputFormatter(o =>
{
o.UseClassNames();
}));
});
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; }
}
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);
}));
});