Monday, 15 March 2010

c# - WCF determine if JSON key sent to server even if value is null -


I'm requesting PUT to update information about a user. Only my key that sends in my code JSON requires revision, it works well, but I would like to include the ability to destroy information.

Currently when I send a request {"firstname": "will"} , de-serialing the WCF object and return the data contract. As a result, the result in one object is:

  UserObject firstname = & gt; Will be, last name = & gt; Zero, gender => Zero  

This is okay, because I only update the values ​​that are not zero. However, when it comes to removing a value, I send {"firstname": null} - the fact that I define the key to the action which I would like to update, the other keys It means leaving them alone.

The problem is that automatic deserialisation gives me an object:

  UserObject firstname = & gt; Zero, Last Name = & gt; Zero, gender => How do I know that I had the key request for updating the prices, should I manually request prices and de-serialize the loop? Or is there any way to contact the data, only given the options to give me options?  

I have tried emitDefaultValue = false but it seems that to serial only the object.

Well, I'll recognize some type of user id. You have the problem, that your primary key (in the database language) can change, which is not a good idea.

An ID can not be changed, and therefore you can always identify the object.


No comments:

Post a Comment