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

Undeclared enum type value for untype value serialized as empty resource #931

Closed
xuzhg opened this issue May 18, 2023 · 0 comments · Fixed by #961
Closed

Undeclared enum type value for untype value serialized as empty resource #931

xuzhg opened this issue May 18, 2023 · 0 comments · Fixed by #961
Assignees
Labels
bug Something isn't working

Comments

@xuzhg
Copy link
Member

xuzhg commented May 18, 2023

Assemblies affected
Which assemblies and versions are known to be affected e.g. ASP.NET Core OData 8.x

Describe the bug
A clear and concise description of what the bug is.

Reproduce steps
If we have

public enum UserType {...}

But this enum is not defined in OData model.

Suppose we use this C# enum to assign a value for a untyped property or dynamic property, the result is empty resource.

Person p = new Person
{
    Data = UserType.Admin  // System.Object Data {get;set;}
}

We get:

"Data": {},

This is because, in "CreateUntypedPropertyValue", we can't get the Edm type for "UserType", then we consider it a resource.
So, goes to the resource serializer, owing that the enum type doesn't have public properties,
so, the final result is an empty resource.

Before the fix, the workaround is to call 'ToString'.

Person p = new Person
{
    Data = UserType.Admin.ToString()
}

Data Model
Please share your Data model, for example, your C# class.

EDM (CSDL) Model
Please share your Edm model, for example, CSDL file.
You can send $metadata to get a CSDL XML content.

Request/Response
Please share your request Uri, head or the request body
Please share your response head, body.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Please share your call stack or any error message
Add any other context about the problem here.

@xuzhg xuzhg added the bug Something isn't working label May 18, 2023
xuzhg added a commit that referenced this issue Jun 19, 2023
xuzhg added a commit that referenced this issue Aug 10, 2023
xuzhg added a commit that referenced this issue Aug 10, 2023
… empty resource (#961)

* fixes #931: Undeclared enum type value for untype value serialized as empty resource

* Update the comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants