I\'m using Json.Net to serialize and deserialize classes to json and back.
I added to a class marked with [JsonObject(ItemRequired = Required.Always)]
(
Evidently JsonIgnore
will only control the serialization in this case. JsonIgnore
is required to specify that the FullName
property should not be serialized to the json representation.
To ignore the property during deserialization we need to add the JsonProperty
annotation with Required = Required.Default
(which means not required).
So, this is how to avoid the JsonSerializationException
:
[JsonObject(ItemRequired = Required.Always)]
public class Hamster
{
public string FirstName { get; set; }
public string LastName { get; set; }
[JsonIgnore]
[JsonProperty(Required = Required.Default)]
public string FullName { get { return FirstName + LastName; }}
}