The issue which was causing this serialization problem was very simple. Check SocialConnectionKind enumeration:
public enum SocialConnectionKind
{
Skype,
Facebook,
Twitter,
LinkedIn,
Hangouts
}
Did you already notice what could be the problem? The issue wouldn't be reproduced if the value would be any excepting Skype!
Why? Enumerations start with 0 and see how I've configured my WebAPI's HttpConfiguration:
config.Formatters.JsonFormatter.SerializerSettings.DefaultValueHandling =
DefaultValueHandling.Ignore;
Which is the default value of the Enum default underlying type int? Yes, it's 0.
So, what solved the issue?
public enum SocialConnectionKind
{
Skype = 1, // <--- The issue was solved starting the enumeration from 1!
Facebook,
Twitter,
LinkedIn,
Hangouts
}
Another approach
As @Avner Shahar-Kashtan have pointed out in some comment, I could also solve this issue using [JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)] attribute:
[DebuggerDisplay("{Kind}: {Identifier}")]
public class SocialConnection
{
public virtual Guid UniqueId
{
get { return Id; }
set { Id = value; }
}
// SocialConnectionKind is an enumeration
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
public virtual SocialConnectionKind Kind { get; set; }
public virtual string Identifier { get; set; }
}
...and this way there's no need of starting an enumeration from 1.
Anyway, in my particular case, I prefer to stay with the start from 1 approach, because I find cleaner avoid polluting my POCOs with serialization-specific attributes because SocialConnection class lives in a shared library and this serialization issue is an implementation issue in a concrete project.