c# - ASP.NET Web API Not Serializing bool fields -
i have following model class:
[datacontract(namespace = "http://api.mycompany.com/v1")] public class job{ [datamember(isrequired = true), required] public long id { get; set; } [datamember(emitdefaultvalue = false)] public datetime? startdate { get; set; } [datamember(emitdefaultvalue = false)] public datetime? enddate { get; set; } [datamember(emitdefaultvalue = false)] public bool iscurrentjob { get; set; } }
for reason when http request, boolean iscurrentjob field not included in serialized response client. there reason might happening? value not null, it's set true.
if change field string, appears no problem in response. of other fields appear in response.
it not desirable use emitdefaultvalue
value types (like bool
). default value bool
false
, that's why gets omitted you.
perhaps intending use nullable bool bool?
instead?
more info here:
in .net framework, types have concept of default values. example, reference type default value null, , integer type 0. desirable omit data member serialized data when set default value. this, set emitdefaultvalue property false (it true default).
setting emitdefaultvalue property false not recommended practice. should done if there specific need (such interoperability or reduce data size).
Comments
Post a Comment