Json2CSharp / Json2CSharpCodeGenerator

Microsoft Reciprocal License
292 stars 81 forks source link

Tool doesn't add nullable field when necessary #82

Closed cajmorgan closed 1 year ago

cajmorgan commented 1 year ago

If you have conflicts, nullable fields aren't generated automatically.

Json2CSharp commented 1 year ago

can you please provide an example for future reference ?

cajmorgan commented 1 year ago

For example:

{
  "id": "WH-77687562XN25889J8-8Y6T55435R66168T6",
  "create_time": "2018-19-12T22:20:32.000Z",
  "resource_type": "subscription",
  "event_type": "BILLING.SUBSCRIPTION.ACTIVATED",
  "summary": "A billing agreement was activated.",
  "resource": {
    "quantity": "20",
    "subscriber": {
      "name": {
        "given_name": "John",
        "surname": "Doe"
      },
      "email_address": "customer@example.com",
      "shipping_address": {
        "name": {
          "full_name": "John Doe"
        },
        "address": {
          "address_line_1": "2211 N First Street",
          "address_line_2": "Building 17",
          "admin_area_2": "San Jose",
          "admin_area_1": "CA",
          "postal_code": "95131",
          "country_code": "US"
        }
      }
    },
    "create_time": "2018-12-10T21:20:49Z",
    "shipping_amount": {
      "currency_code": "USD",
      "value": "10.00"
    },
    "start_time": "2018-11-01T00:00:00Z",
    "update_time": "2018-12-10T21:20:49Z",
    "billing_info": {
      "outstanding_balance": {
        "currency_code": "USD",
        "value": "10.00"
      },
      "cycle_executions": [
        {
          "tenure_type": "TRIAL",
          "sequence": 1,
          "cycles_completed": 1,
          "cycles_remaining": 0,
          "current_pricing_scheme_version": 1
        },
        {
          "tenure_type": "REGULAR",
          "sequence": 2,
          "cycles_completed": 1,
          "cycles_remaining": 0,
          "current_pricing_scheme_version": 2
        }
      ],
      "last_payment": {
        "amount": {
          "currency_code": "USD",
          "value": "500.00"
        },
        "time": "2018-12-01T01:20:49Z"
      },
      "next_billing_time": "2019-01-01T00:20:49Z",
      "final_payment_time": "2020-01-01T00:20:49Z",
      "failed_payments_count": 2
    },
    "links": [
      {
        "href": "https://api.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G",
        "rel": "self",
        "method": "GET"
      },
      {
        "href": "https://api.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G",
        "rel": "edit",
        "method": "PATCH"
      },
      {
        "href": "https://api.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/suspend",
        "rel": "suspend",
        "method": "POST"
      },
      {
        "href": "https://api.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/cancel",
        "rel": "cancel",
        "method": "POST"
      },
      {
        "href": "https://api.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/capture",
        "rel": "capture",
        "method": "POST"
      }
    ],
    "id": "I-BW452GLLEP1G",
    "plan_id": "P-5ML4271244454362WXNWU5NQ",
    "auto_renewal": true,
    "status": "ACTIVE",
    "status_update_time": "2018-12-10T21:20:49Z"
  },
  "links": [
    {
      "href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-77687562XN25889J8-8Y6T55435R66168T6",
      "rel": "self",
      "method": "GET",
      "encType": "application/json"
    },
    {
      "href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-77687562XN25889J8-8Y6T55435R66168T6/resend",
      "rel": "resend",
      "method": "POST",
      "encType": "application/json"
    }
  ],
  "event_version": "1.0",
  "resource_version": "2.0"
}
cajmorgan commented 1 year ago

I added this to fix:

[JsonPropertyName("encType")]
        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        public string? EncType { get; set; }