Open
Description
We use the aspnetcore 2.
We have configured JsonOptions in startup like this.
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
options.SerializerSettings.Converters = new List<JsonConverter> {
new JsonDocumentConverter(),
new JsonDocumentMetaConverter(),
//new Bll.FileRecords.JsonDocumentMetaListConverter(),
};
});
public class JsonDocumentConverter : CustomCreationConverter<IDocument>
{
public override IDocument Create(Type objectType)
{
return new LocalDocument();
}
}
public class JsonDocumentMetaConverter : CustomCreationConverter<IDocumentMeta>
{
public override IDocumentMeta Create(Type objectType)
{
return new LocalDocumentMeta();
}
}
In our controller we have 2 methods
- The first one is called PostUrlencoded in which we make a http post request with content-type : application/x-www-form-urlencoded.
[HttpPost("PostUrlencoded")]
public async Task<IActionResult> PostUrlencoded([FromBody]IDocument document)
{ /*...*/ }
2.. The second one is called PostΜultipart in which we make a http post request with content-type : multipart/form-data.
[HttpPost("PostΜultipart")]
public async Task<IActionResult> PostΜultipart([FromForm]IDocument document)
{ /*...*/ }
The first method works fine, and the deserialization works fine. In the second method deserialization fails.
The error is:
Model bound complex types must not be abstract or value types and must have a parameterless constructor.
That's because the JsonOptions isn't applied.
When we remove the jsonOptions from the startup.cs, we get the same error in both cases.
Metadata
Metadata
Assignees
Labels
This issue requires design work before implementating.This issue impacts approximately half of our customersIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesThis issue represents an ask for new feature or an enhancement to an existing oneThis label is used by an internal tool