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
{{ message }}
Repository navigation
Change serializer settings to not send empty values, and deserialize empty collections #3381
With our current serializer settings there is difference between sending null, and sending empty collection. The serializer will do "the right thing" and give you what you sent. So either a null or empty collection. If no-one touches the property, or does not re-assign it to null we will get empty list on the other side.
IMHO there is almost never a case where you want to know if the collection was null, or empty, and we should change our serializer settings to:
not send empty or null values
always populate collections with empty collection even if we receive null, unless opted out (and I cannot recall any place where we would want to do that)
usingConsoleDump;usingMicrosoft.VisualStudio.TestPlatform.CommunicationUtilities;// See https://aka.ms/new-console-template for more informationConsole.WriteLine("Hello, World!");JsonDataSerializer.Instance.DeserializePayload<AAA>(JsonDataSerializer.Instance.DeserializeMessage(JsonDataSerializer.Instance.SerializePayload("mmm",newAAA())).Dump()).Dump();JsonDataSerializer.Instance.DeserializePayload<BBB>(JsonDataSerializer.Instance.DeserializeMessage(JsonDataSerializer.Instance.SerializePayload("mmm",newBBB())).Dump()).Dump();publicclassAAA{publicIList<string>Names{get;set;}=newList<string>();}publicclassBBB{publicIList<string>Names{get;set;}}
Screenshot shows the message on the receiving side before deserialization of the payload (yellow) and after deserialization (green).
In the approach I propose, the payload for both AAA and BBB would be empty ({}) and Names would deserialize as empty collection for both AAA and BBB.
Nullability would help in our code to prevent us from setting null but we cannot control outside of our boundaries (e.g. user or serializer could set null). The only real safety would be to either prevent public setter or to have a backing field and check we don't pass null.
Activity
Evangelink commentedon Feb 17, 2022
Nullability would help in our code to prevent us from setting null but we cannot control outside of our boundaries (e.g. user or serializer could set
null). The only real safety would be to either prevent public setter or to have a backing field and check we don't passnull.nohwnd commentedon Jul 8, 2024
This is a new feature and won't be implemented, we are focusing on adding new features to Testing.Platform instead. https://aka.ms/testingplatform
Add regression tests for untested bug fixes
Add 365 regression tests for untested bug fixes (#15615)