I'm using newtonsoft JSON.NET library to serialize a object of a thrid party library which I can't modify. Some of the properties of this object serialize to an empty string although they have value. So I want to call the ToString to get and serialize the value only for the properties that are of certain type.
namespace ThirdParty.Lib
{
public class Info
{
// When newtonsoft serialize a property of this type (CDataField)
// a get an empty string as value.
public CDataField Name { get; set; }
public CDataField Email { get; set; }
public string IdNNumber {get; set;}
}
}
var info = new ThirdParty.Lib.Info
{
IdNumber = "001254810",
Name = "John Doe",
Email = "[email protected]"
};
var jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(transactionModel)
//json string output
{ IdNumber: "001254810", Name: "", Email: "" }