Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Dynamic CRM : Ignore DATETIME.MINVALUE JsonConvert C#

Posted on by 5

Hello community , 

I have to convert a object to json string I try to ignore the properties with a minvalue datetime in my Json string 

this is my code convert :

string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(customerB2B, Formatting.Indented, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});

this is my Json : 

json.png

This is my class object :

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace OCM.XRM.Plugins.Objects
{

public class CustomerB2B
{

public string id { get; set; }
public string custNmae { get; set; }
public string custType { get; set; }
public string businessRegister { get; set; }
 public DateTime certificateIssueDate { get; set; }
public DateTime certificateExpireDate { get; set; }
public DateTime createDate{ get; set; }

public DateTime updateDate{ get; set; }

}

Does any one Have an idea how to ignore a datetime with a minvalue ? 

Pleassse let me know !!

Ps: I work on CRM 2015 on premises 

 

*This post is locked for comments

  • Jamil Lamyae Profile Picture
    Jamil Lamyae 5 on at
    RE: Dynamic CRM : Ignore DATETIME.MINVALUE JsonConvert C#

    Thanks a lot Shaminderpal for your reply

    it works fine I used //NullValueHandling = NullValueHandling.Ignore, instead of DefaultValueHandling = DefaultValueHandling.Ignore

  • Verified answer
    Shaminderpal Singh Profile Picture
    Shaminderpal Singh 1,565 on at
    RE: Dynamic CRM : Ignore DATETIME.MINVALUE JsonConvert C#

    Hi,

    Could you try below:

    string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(customerB2B, Formatting.Indented, new JsonSerializerSettings

    {

    DefaultValueHandling = DefaultValueHandling.Ignore

    });

    -Shaminder

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans