You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new recommended way of defining that null items should be ignored by the json serializer (System.Text.Json) is to add a JsonIgnore attribute, with a condition, like this:
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
A JsonSerializerOptions instance can be used instead, but there is currently no way of applying this to the built in httpClient methods - GetFromJson, PostAsJson and PutAsJson
However, the odata client does not respect this condition, and ignores the property during deserialization and serialization despite the property having a value.
The text was updated successfully, but these errors were encountered:
I was trying to decorate entity properties as follows
class MyEntity
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public Guid MyProperty{ get; set; }
}
The expected behaviour is not to send this property when trying to insert/update if it is not set.
But when getting list of entities from a GET query and it was a part of the response it should be set.
Currently is is ignored in both POST and GET calls
The new recommended way of defining that null items should be ignored by the json serializer (System.Text.Json) is to add a JsonIgnore attribute, with a condition, like this:
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
A JsonSerializerOptions instance can be used instead, but there is currently no way of applying this to the built in httpClient methods - GetFromJson, PostAsJson and PutAsJson
Official documentation here: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/ignore-properties?pivots=dotnet-7-0
However, the odata client does not respect this condition, and ignores the property during deserialization and serialization despite the property having a value.
The text was updated successfully, but these errors were encountered: