Deserializing empty string

Oct 19, 2009 at 4:47 PM

I just tried upgrading my app from beta3 to r5 and noticed that empty strings are now deserialized to null rather than empty string. I saw the release note that said "Change - Empty string to be deserialized as null for nullable types", and string is a nullable type.  For my app, I'd prefer to stay with empty string being deserialized to empty string for String types, and be null for other nullable types. Can you recommend the best way to go about doing this?

Nov 2, 2009 at 8:31 PM

I've checked in a fix for this.

Nov 2, 2009 at 9:38 PM

Great, thank you!

Mar 10, 2010 at 6:15 AM
Edited Mar 10, 2010 at 6:39 AM

I just had the same problem. Unfortunately my legacy app assumes that all null values will be empty string.

I haven't found a way to do this yet, but is this a setting? Or could/should it be?

eg (This is not quite the right syntax but you get the idea...)

return JsonConvert.SerializeObject(o, Formatting.Indented, new JsonSerializerSetting { NullAsEmptyString = true; }