My json array, which comes to me from the server, can contain empty string elements. I want to remove them at the level of deserialization.
{
"Highlights":[
"Þingvellir National Park",
"Gullfoss Waterfall",
"Geysir Geothermal Area",
"Laugarvatn","Kerið Crater",
"Hveragerði Hot Spring Area",
"",
""
]
}
Model:
public class TestModel
{
public List<string> Highlights { get; set; }
}
I want that if the element is string.IsNullOrEmpty (element) == true, then it is not added to the array.
In this case, the number of elements after deserialization in the TestModel.Highlights array should be 6, not 8, because 2 of them are empty.
How can I achieve this?
Where(s => !string.IsNullOrEmpty(s))onHighlightsJsonConverterwould be probably very YAGNI :)