but i don’t deserialize anything, i don’t understand.
You might not do it directly, but you certainly ask the framework to deserialize something for you:
[HttpPost]
public async Task<IActionResult> UpdateEquipment(EquipementDto equipment)
Here you tell the framework you expect the call to contain a serialized string of json representing an object matching your EquipementDto
and to please deserialize that string for you into an actual instance of the EquipementDto
and pass that to the method.
So now that we’ve determined where the deserialization takes place we can take a look at what’s going on. During deserialization the framework that does the deserialization needs to be able to construct the object you want deserialized.
To be able to construct that object it needs a valid constructor. It seems like it’ll accept 2 types of constructors:
- An empty constructor
- A constructor with parameters that match the property names of the object (so instead of setting the properties directly the framework can populate them through the constructor.
Your EquipementDto
has only 1 constructor and that constructor takes some unknown EquipmentEntity
that the deserialization framework knows nothing about.
Now I’m not completely sure but I think this will be solved by just adding a parameterless constructor to your EquipementDto
class:
[JsonConstructor]
public EquipementDto(){}