OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
686 stars 349 forks source link

When calling unbound action with entitytypes with value null, the sent json contains the null values #2692

Open KristianHebert opened 1 year ago

KristianHebert commented 1 year ago

Null values should be omitted as stated in the documentation: https://learn.microsoft.com/en-us/odata/webapi/action-parameter-support#null-value And the the null value is not accepted by the server which fails with an invalid modelstate. If the null valued entities are omitted, the Action works.

Assemblies affected

OData 7.16.0

Odata connected service 2022+

Microsoft Visual Studio Enterprise 2022 (64-bit) Version 17.5.4

Reproduce steps

Make an action that takes an entity parameter and checks for ModelState.IsValid

if the entity is sent with value = null, the modelstate is invalid, and no other parameters can be read.

Expected result

Client should generate a message without the entity in the posted json, when the value is null. This is accepted by the server.

Actual result

The client generates a message with the entity, and a value of null: {"CustomerText":null}

This is rejected by the server

KristianHebert commented 1 year ago

I tried to modify the request by looking at the OnEntryStarting event, but this does not seem to be working anymore, and the unittests have been commented away three years ago.