odata.net icon indicating copy to clipboard operation
odata.net copied to clipboard

Implement int to enum deserialization.

Open bdebaere opened this issue 5 years ago • 5 comments

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

bdebaere avatar Nov 01 '19 12:11 bdebaere

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 avatar Nov 04 '19 15:11 adzhilyanov

@adzhilyanov I'd be happy to merge, I haven't gotten around to it yet.

bdebaere avatar Nov 13 '19 12:11 bdebaere

@xuzhg , @KanishManuja-MS could we get your review on this?

odero avatar Feb 27 '20 09:02 odero

When will be done this issue ?

SenyaMur avatar Jul 02 '20 05:07 SenyaMur

@bdebaere Kindly work on review comments.

KenitoInc avatar Jan 22 '21 08:01 KenitoInc