Deserializing when value properties dont exist in the json

Jun 8, 2011 at 4:35 PM
Edited Jun 8, 2011 at 4:42 PM

If i try and deserialize this JSON:




class MyClass{

    public ValueType Val { get; set; }


I get:

JsonSerializationException: Error setting value to 'Val'

NullReferenceException: Object reference not set to an instance of an object.
   at SetVal(Object , Object )   at Newtonsoft.Json.Serialization.DynamicValueProvider.SetValue(Object target, Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\DynamicValueProvider.cs:line 82


Is there a way to make this not fail, and just leave the property with its default value?

Update: im aware of ObjectCreationHandling, I assume setting this to Replace would help? But what does that do for the rest of my settings:



TypeNameHandling = TypeNameHandling.Objects,

ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,

PreserveReferencesHandling = PreserveReferencesHandling.Objects