0

Basically I want to make my script service only serialise properties that are not null on an array of object I am returning... So this..

{"k":"9wjH38dKw823","s":10,"f":null,"l":null,"j":null,"p":null,"z":null,"i":null,"c":null,"m":0,"t":-1,"u":2}

would be

{"k":"9wjH38dKw823","s":10,"m":0,"t":-1,"u":2}

Does anyone know if this is possible?

Basically the reason for this is because null values are for unchanged properties. A local copy is kept in the javascript that is just updated to reduce traffic to the server. Change values are then merged.

1
  • What kind of object are you using that has these properties? Is it a particular class? Dictionary<string, string>? Commented May 10, 2011 at 17:11

1 Answer 1

1

You can create a custom JavaScriptConverter class for the JSON serialization process to use to handle your object, and then put the necessary logic in the Serialize method of that class to exclude the properties that are null.

This article has a clear step-by-step discussion of the process involved in creating it.

You probably would not need to actually implement the Deserialize method (can throw a NotImplementedException) if you are not passing that type of object in as an input parameter to your web services.

Sign up to request clarification or add additional context in comments.

1 Comment

This did the job perfectly thank you. Its also useful for some other issues too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.