This project has moved and is read-only. For the latest updates, please go here.

Deserializing empty string

Oct 19, 2009 at 5: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 9:31 PM

I've checked in a fix for this.

Nov 2, 2009 at 10:38 PM

Great, thank you!

Mar 10, 2010 at 7:15 AM
Edited Mar 10, 2010 at 7: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; }