Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SmartEnum not deserialized as path parameter #339

Open
BrianFreemanAtlanta opened this issue Nov 20, 2022 · 2 comments
Open

SmartEnum not deserialized as path parameter #339

BrianFreemanAtlanta opened this issue Nov 20, 2022 · 2 comments

Comments

@BrianFreemanAtlanta
Copy link

I have a controller that uses SmartEnum as a path parameter:

[HttpGet]
        [Route("{clientApiIdentifier}/FilterListSmart/{columnId}")]
        public async Task<List<dynamic>> GetFilterListSmart(
            [FromRoute] string clientApiIdentifier,
            [FromRoute] FormsReportColumnsSmart columnId)

When I call my controller it doesn't deserialize the value for columnId. columnId is always "Unknown".
example call:
{{ReportingApiUrl}}/Forms/{{clientId}}/FilterListSmart/CandidateId

I tried a test case calling deseriallize on a string and "AssignedTo" works but AssignedTo doesn't. Am I missing something? or is this an issue?

Initially I got errors from MVC binding for abstract class and parameterless constructor needed. I ended up with this class:

    [JsonConverter(typeof(SmartEnumValueConverter<FormsReportColumnsSmart, int>))]
    public class FormsReportColumnsSmart : SmartEnum<FormsReportColumnsSmart>
    {
        public static readonly FormsReportColumnsSmart CandidateId = new CandidateIdCol();
        public static readonly FormsReportColumnsSmart FormattedName = new FormattedNameCol();
        public static readonly FormsReportColumnsSmart UserApiIdentifier = new UserApiIdentifierCol();
        public static readonly FormsReportColumnsSmart ProcessFlowName = new ProcessFlowNameCol();
        public static readonly FormsReportColumnsSmart FormName = new FormNameCol();
        public static readonly FormsReportColumnsSmart FormType = new FormTypeCol();
        public static readonly FormsReportColumnsSmart FormStatus = new FormStatusCol();
        public static readonly FormsReportColumnsSmart FormStatusSort = new FormStatusSortCol();
        public static readonly FormsReportColumnsSmart FormDueDate = new FormDueDateCol();
        public static readonly FormsReportColumnsSmart CompletionDate = new CompletionDateCol();
        public static readonly FormsReportColumnsSmart FormStatusIdentifier = new FormStatusIdentifierCol();
        public static readonly FormsReportColumnsSmart AssignedTo = new AssignedToCol();
        public static readonly FormsReportColumnsSmart AssignedToId = new AssignedToIdCol();
        public static readonly FormsReportColumnsSmart RowId = new RowIdCol();
        public static readonly FormsReportColumnsSmart Unknown = new UnknownIdCol();
        private FormsReportColumnsSmart(string name, int value) : base(name, value)
        {
        }
        public FormsReportColumnsSmart() : base(nameof(Unknown), 1)
        {
        }
        public FormsReportColumnsSmart(string name) : base(name, 1)
        {
        }
        private sealed class UnknownIdCol : FormsReportColumnsSmart
        {
            public UnknownIdCol() : base(nameof(Unknown), 1)
            {
            }
        }

        private sealed class CandidateIdCol : FormsReportColumnsSmart
        {
            public CandidateIdCol() : base(nameof(CandidateId), 1)
            {
            }
        }
        private sealed class FormattedNameCol : FormsReportColumnsSmart
        { 
            public FormattedNameCol() : base(nameof(FormattedName), 2) 
            {
            } 
        }
        private sealed class UserApiIdentifierCol : FormsReportColumnsSmart 
        { 
            public UserApiIdentifierCol() : base(nameof(UserApiIdentifier), 3) 
            { 
            } 
        }
        private sealed class ProcessFlowNameCol : FormsReportColumnsSmart 
        { 
            public ProcessFlowNameCol() : base(nameof(ProcessFlowName), 4) 
            { 
            } 
        }
        private sealed class FormNameCol : FormsReportColumnsSmart 
        { 
            public FormNameCol() : base(nameof(FormName), 5) 
            { 
            } 
        }
        private sealed class FormTypeCol : FormsReportColumnsSmart 
        { 
            public FormTypeCol() : base(nameof(FormType), 6) 
            { 
            } 
        }
        private sealed class FormStatusCol : FormsReportColumnsSmart 
        { 
            public FormStatusCol() : base(nameof(FormStatus), 7) 
            { 
            } 
        }
        private sealed class FormStatusSortCol : FormsReportColumnsSmart 
        { public FormStatusSortCol() : base(nameof(FormStatusSort), 8) 
            { 
            } 
        }
        private sealed class FormDueDateCol : FormsReportColumnsSmart 
        { 
            public FormDueDateCol() : base(nameof(FormDueDate), 9) 
            { 
            } 
        }
        private sealed class CompletionDateCol : FormsReportColumnsSmart 
        { 
            public CompletionDateCol() : base(nameof(CompletionDate), 10) 
            { 
            } 
        }
        private sealed class FormStatusIdentifierCol : FormsReportColumnsSmart 
        { 
            public FormStatusIdentifierCol() : base(nameof(FormStatusIdentifier), 11) 
            { 
            } 
        }
        private sealed class AssignedToCol : FormsReportColumnsSmart 
        { 
            public AssignedToCol() : base(nameof(AssignedTo), 12) 
            { 
            } 
        }
        private sealed class AssignedToIdCol : FormsReportColumnsSmart 
        { 
            public AssignedToIdCol() : base(nameof(AssignedToId), 13) 
            { 
            } 
        }
        private sealed class RowIdCol : FormsReportColumnsSmart 
        { 
            public RowIdCol() : base(nameof(RowId), 14) 
            { 
            } 
        }


    }
@essuraj
Copy link

essuraj commented Apr 12, 2023

or FromQuery or FromHeader

@muratyuceer
Copy link

Yes, I have same question @ardalis ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants