Jump to content
Sign in to follow this  
pyscripter

Ignoring nil values with ΤJsonSerializer

Recommended Posts

When I serialize a an object with object fields that are nil  I get null values in the Json result e.g.

 

 
{
    "capabilities": {
        "positionEncoding": [],
        "textDocumentSync": {
            "openClose": true,
            "change": 2,
            "willSave": false,
            "willSaveWaitUntil": false,
            "save": null
        },
        "notebookDocumentSync": null,
        "completionProvider": null,
}

 

How can I ignore fields that have nil values?


System.JSON.Types defines the following:

  TJsonDefaultValueHandling = (Include, Ignore, Populate, IgnoreAndPopulate);

but it is not used anywhere.

 

I also tried to use a converter, but I could not get it to work.  And in any case converters are used after the property name is written.

 

Any ideas?

Edited by pyscripter

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×