0
public string Name{ get; set; }

Hi Team, I'm new to json ignore thing. I went through lot of other solutions for ignore my string property from json. but the thing was, Custom converter is not practical for to my code, because it has lot of properties to read and write.

So we have only these 3 option to ignore property without creating custom converter.

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]

In case of string, string default value also null. So how can I simply ignore this string property when it has specific value? Btw i need to do this without creating custom converter

Charlieface
  • 52,284
  • 6
  • 19
  • 43
Harendrra
  • 107
  • 1
  • 10
  • Maybe just write out the `Name` property as a full property (not auto) and put the condition in the setter – Charlieface Jul 03 '22 at 13:08
  • You have to post an example of json you have now and example what do you want – Serge Jul 03 '22 at 14:13
  • 1
    *Btw i need to do this without creating custom converter* -- using a custom converter **is** the way to do this, because System.Text.Json does not support `DefaultValueAttribute` to specify custom default values, see [this answer to *How to ignore false values with System.Text.Json*](https://stackoverflow.com/a/59295144/3744182) for confirmation. Your other options would seem to include modifying your class to have a synthetic property, or using a 3rd party add-on converter such as the one mentioned in [this answer](https://stackoverflow.com/a/59295144/3744182). – dbc Jul 03 '22 at 21:06
  • 1
    Why do you “need” to do it without a custom converter? – scottdavidwalker Jul 03 '22 at 21:15
  • Thanks for the all comments. I know a custom converter is a solution for this. but I'm working with production data. so that's why I don't need to use a custom converter because it might affect to a couple of places. – Harendrra Jul 04 '22 at 04:53
  • Can you change the c# classes? – dbc Jul 04 '22 at 16:05

0 Answers0