1

I am trying to return a JSON dataset that looks like the following. Let me caveat this by saying I am restricted to Visual Studio 2010 and .NET 4.0. how do I either output the NULL or convert to blank?

  "Application": {
  "AppID": 3119385,
  "ReportID": 4171130,
  "AppReference": "Doran 23-Nov-16 10:46:59AM",
  "CreateDT": "2016-11-23 10:48:38.5800000",
  "ClientName": "GoGetta Brisbane",
  "StoreName": "Brokers",
  "Email": "",
  "StoreCode": "GGT08",
  "AppShortReference": "02",
  "ClientNameShort": "GGT Bris",
  "StoreNameShort": "GGT08",
  "VerifyEmployer": null,
  "VerifyAmount": null,
  "VerifyFrequency": null,
  "VerifyWeekday": null,
  "LocalityCode": "en_AU",
  "TemplateReportID": 12,
  "daysRange": 90,
  "templateReportName": "Enhanced Income Liabilities Full Report",
  "isReportGraphEnabled": 1,

I am trying to process this into an output buffer of a script component in SSIS. However I keep getting a "cannot convert null to value type" error despite checking for it.

  if (String.IsNullOrEmpty(rptContentOutput.Applications.Application.VerifyEmployer) == true)
            {
                ApplicationDetailsBuffer.VerifyEmployer = "";
            }
            else
            {
                ApplicationDetailsBuffer.VerifyEmployer = rptContentOutput.Applications.Application.VerifyEmployer;
            }

My class has been defined as the following.

public class Application
{
    [JsonProperty("AppID")]
    public int? AppID { get; set; }
    [JsonProperty("ReportID")]
    public int? ReportID { get; set; }
    [JsonProperty("AppReference")]
    public string AppReference { get; set; }
    [JsonProperty("CreateDT")]
    public string CreateDT { get; set; }
    [JsonProperty("ClientName")]
    public string ClientName { get; set; }
    [JsonProperty("StoreName")]
    public string StoreName { get; set; }
    [JsonProperty("Email")]
    public string Email { get; set; }
    [JsonProperty("StoreCode")]
    public string StoreCode { get; set; }
    [JsonProperty("AppShortReference")]
    public string AppShortReference { get; set; }
    [JsonProperty("ClientNameShort")]
    public string ClientNameShort { get; set; }
    [JsonProperty("StoreNameShort")]
    public string StoreNameShort { get; set; }
    [JsonProperty("VerifyEmployer")]
    public string VerifyEmployer { get; set; }
    [JsonProperty("VerifyAmount")]
    public double VerifyAmount { get; set; }
    [JsonProperty("VerifyFrequency")]
    public string VerifyFrequency { get; set; }
    [JsonProperty("VerifyWeekday")]
    public string VerifyWeekday { get; set; }
    [JsonProperty("LocalityCode")]
    public string LocalityCode { get; set; }
    [JsonProperty("TemplateReportID")]
    public int? TemplateReportID { get; set; }
    [JsonProperty("daysRange")]
    public int? daysRange { get; set; }
    [JsonProperty("templateReportName")]
    public string templateReportName { get; set; }
    [JsonProperty("isReportGraphEnabled")]
    public string isReportGraphEnabled { get; set; }

}

Lucas Perrett
  • 423
  • 1
  • 6
  • 16
  • You don't specify what is `VerifyFrequency` - are those classes or structs? – LB2 May 31 '17 at 00:10
  • @LB2 what do you mean. I am not outputting that as yet because I could get the first value out. – Lucas Perrett May 31 '17 at 00:12
  • Perhaps I misunderstood the question: are you trying to serialize into JSON, or deserialize from JSON? – LB2 May 31 '17 at 00:15
  • What is the type for `ApplicationDetailsBuffer.VerifyEmployer`. Please show the code – CodingYoshi May 31 '17 at 00:18
  • @LB2 I am Deserializing from JSON to Output Buffer. – Lucas Perrett May 31 '17 at 00:18
  • So if you're deserializing into your `Application` model, it's important to understand what `VerifyFrequency` (and the like) are. If those are structs, then the issue is clear - they're not declared `Nullable`. If not, then it's something else. – LB2 May 31 '17 at 00:20
  • Also, it's not clear what that code snipped is about, or what context it is in. Can you show more context? – LB2 May 31 '17 at 00:21
  • @CodingYoshi it is a string as defined in my class. ApplicationDetailBuffer is the output for my SSIS package and is also defined as a string. – Lucas Perrett May 31 '17 at 00:21
  • Sorry for misleading comments - somehow I didn't see the `string` type and thought `VerifyEmployer` was a type, not name of property. – LB2 May 31 '17 at 00:28

1 Answers1

1

Ok, I misread the code with prior comments, but I see it now.

The issue is:

public double VerifyAmount { get; set; }

which is a value type, and the JSON contains:

"VerifyAmount": null,

which causes the error. The fix is:

public double? VerifyAmount { get; set; }
LB2
  • 4,802
  • 19
  • 35
  • THANK YOU!!!! I have been looking at this for hours but clearly focusing on the wrong end of the equation. I though because I was not outputting it, that it wasn't being used. – Lucas Perrett May 31 '17 at 00:29