Deserialize wrapper object in route
Hello.
Does anyone know if it is possible to map deserilize a custom wrapper object in a route?
IDs in my system is strings, and we have therefore made an
External
class.
The only point of this, is to improve code readability, to easy be able to view what is ids, and what is not.
We have made a serilizer, that maps maps the class to a string in any JSON schemes.
However, this serilizer does not seem to work, when we use the class in a route.
Can we do it via a serilizer or some middleware, or do I have to take a string as input, and map it to ExternalId
in my controller?
6 Replies
This should work, just maybe get rid of the constructor
Serialization generally requires a default ctor to be present, the easiest way to do that is to... just not define any ctor at all
I do have a no args construtor, just removed it to keep the code simpel.
However, the id is just a ExternalId, with the inner string being null
Try
[HttpGet("{Id}")]
Casing might matterAhh... I found the fix, thanks to you!
The issue was not spacing, but that my parameter was also named
id
To fix this, I have to rename my outer id to something else
Thanks for the help!Ah, yeah, that makes sense
Glad you got it sorted