It took me a while to find out that the model/DTO using public fields are not deserialized and model bound during a JSON post request. After changing the fields to properties the server everything works fine. Any reason for that? Pretty frustrating though.
Thanks.
Used to be that my DTOs are POCOs and no xml annotation/attribute are used, the WCF generate the proxy classes for the properties using {get;set;} with the hidden auto-gen fields name. By using fields I got the proxy classes member names straight (maybe
you know a better way to do this). So just found out that WebAPI only takes properties: guess just it's just-by-design and I can live with that:-)
This behavior should be fixed in the next drop. Then, each serializer will define what types of members it supports. Both JSON and XML will support public fields.
lawdl9933
Member
6 Points
4 Posts
Model using public fields are not deserialized during post
Mar 16, 2012 02:53 PM|LINK
It took me a while to find out that the model/DTO using public fields are not deserialized and model bound during a JSON post request. After changing the fields to properties the server everything works fine. Any reason for that? Pretty frustrating though. Thanks.
SiggiGG
Member
265 Points
105 Posts
Re: Model using public fields are not deserialized during post
Mar 16, 2012 03:13 PM|LINK
Any specific reason you want to use public fields? I havent done that in many many years.
lawdl9933
Member
6 Points
4 Posts
Re: Model using public fields are not deserialized during post
Mar 16, 2012 07:25 PM|LINK
Used to be that my DTOs are POCOs and no xml annotation/attribute are used, the WCF generate the proxy classes for the properties using {get;set;} with the hidden auto-gen fields name. By using fields I got the proxy classes member names straight (maybe you know a better way to do this). So just found out that WebAPI only takes properties: guess just it's just-by-design and I can live with that:-)
Thank you!
lawdl9933
Member
6 Points
4 Posts
Re: Model using public fields are not deserialized during post
Mar 16, 2012 07:45 PM|LINK
To make it clear: I meant I didn't use DataContract/DataMember attributes for the POCO DTOs: the only reason to use fields instead of properties.
bradwils
Contributor
5779 Points
691 Posts
Microsoft
Re: Model using public fields are not deserialized during post
Mar 17, 2012 12:45 AM|LINK
This behavior should be fixed in the next drop. Then, each serializer will define what types of members it supports. Both JSON and XML will support public fields.
lawdl9933
Member
6 Points
4 Posts
Re: Model using public fields are not deserialized during post
Mar 18, 2012 03:05 PM|LINK
that sounds a good plan! Thank you.