#jsondotnet
Explore tagged Tumblr posts
markcoleman · 12 years ago
Text
AngularJs, Json.Net, and the $type property
We use the Json.Net serializer in our project and while performing a post that deserializes into a derved class we would also serilization exceptions. We enabled Json.net to emit the $type property so this should be working without problems. Opening up Firebug we quickly realized that the $type property was missing from the request, what gives?
Digging in a bit further it appears that for some reason AngularJs was stripping any property that has a $ sign in the name.  Looking further into the source the problem is in the toJsonReplacer function.
The reason this happens is so Angular doesn't accidentally post angularjs ($$hashkey for instance) properties to the backend, but in this case we need the $type property to go along so Json.Net remains happy.
This can easily be accomplished by replacing the default transformRequest function on the $httpProvider.
https://gist.github.com/markcoleman/5085650
Now Angular is happy and Json.net is happy!
0 notes