© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
10 replies
Arkobat

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
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
ExternalId
in my controller?
    [HttpGet("{id}")]
    public async Task<MyDTO> GetSomething([FromRoute] ExternalId id)
    {
        var result = await _service.GetSomething(id);
        return result.ToDTO();
    }
    [HttpGet("{id}")]
    public async Task<MyDTO> GetSomething([FromRoute] ExternalId id)
    {
        var result = await _service.GetSomething(id);
        return result.ToDTO();
    }

public class ExternalId
{
    public string Id { get; set; }

    public ExternalId() {}
    public ExternalId(string id)
    {
        Id = id;
    }
public class ExternalId
{
    public string Id { get; set; }

    public ExternalId() {}
    public ExternalId(string id)
    {
        Id = id;
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Deserialize JSON back into custom object
C#CC# / help
17mo ago
How to deserialize only child object
C#CC# / help
2y ago
❔ deserialize in csharp
C#CC# / help
4y ago
❔ Deserialize Object that can have both Array and Object structure
C#CC# / help
3y ago