简体   繁体   中英

Migrating to Asp.net core 3 changed the controller response?

after updating to Asp.net core 3 from 2.2 I have encountered a different behaviour from my response that I'm getting from my test controller.

In my controller I want to return all objects that inherit from "ImyInterface".Until now that worked fine. But after updating I will get a response just like in picture 1, but as you see in picture 2 the first object in the list has a lot more attributes.

picture 1 picture 2

Both objects in the list inherit from that Interface and I can use alle the attributes in the program. So it works fine. Only the response is, I think somewhat broken..

I don't know why it is shrinking the first object suddenly. Weird is if I change the return type of the function from IEnumerable to IEnumerable the reponse is completely fine.

Should I inherit from an abstract class instead? has something changed in the new .net version? Has anyone ever seen this or has some ideas why this could happen??

Thanks in advance:)

This could have something to do with the new JSON serializer. Have you tried re-enabling JSON.NET?

https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#jsonnet-support

You have to add JSON.NET like this:

services.AddMvc()
    .AddNewtonsoftJson();

There is also an overload of AddNewtonsoftJson() where you can configure serializer settings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM