odata.net
odata.net copied to clipboard
Implement int to enum deserialization.
Issues
This pull request fixes issue https://github.com/OData/WebApi/issues/1902.
Description
Reads a PrimitiveValue instead of a StringValue and tries to convert the value to an enum.
Checklist (Uncheck if it is not completed)
- [ ] Test cases added
- [ ] Build and test with one-click build and test script passed
Hey,
I posted an issue about enum deserialization, where the read value is not checked against the metadata (#1593). I was about to make a PR about it, but i saw this PR, which is touching the same method. It would be easier to merge if the fix is applied as part of this PR, if everybody is ok with it of course. @bdebaere what do you think about adding something like:
if (selectedMember == null && this.MessageReaderSettings.ThrowIfTypeConflictsWithMetadata)
{
throw new ODataException(Strings.ValidationUtils_EnumMemberDoesNotExistOnType(enumValue, propertyName, edmEnumType.FullTypeName()));
}
and you must always try to get the selectedMember
and
where ValidationUtils_EnumMemberDoesNotExistOnType is something like:
"The value '{0}' for property '{1}' does not exist on enum type '{2}'. Make sure to only use enum members that are defined by the type."
or we can extend ReaderValidationUtils with a similar to https://github.com/OData/odata.net/blob/1e094dcfcabf81d9f668cbc6666945618b1e9023/src/Microsoft.OData.Core/ReaderValidationUtils.cs#L118 method and call it when deserializing the enum value.
Thanks!
@adzhilyanov I'd be happy to merge, I haven't gotten around to it yet.
@xuzhg , @KanishManuja-MS could we get your review on this?
When will be done this issue ?
@bdebaere Kindly work on review comments.