0
votes

I've got an issue when deserializing a JSON string where the PropertyNames with underscores give a NULL value when converting to .NET objects.

The request -

private string GetAuctionRegistrations()
    {
        RestClient client = new($"{am_baseURL_v2}{am_q_auction}{am_auctionID}/{am_reg}?o=0&n=1000");
        RestRequest request = new();
        request.AddHeader("Authorization", am_token);
        var response = client.Execute(request);
        return response.Content;
    }

The response -

{
            "auction_id": "4-6GKA1V",
            "approved_at": null,
            "reviewed_at": null,
            "submitted_at": null,
            "created_at": "2022-06-24T09:05:39.329Z",
            "updated_at": "2022-06-24T09:05:39.329Z",
            "paddle": "1001",
            "account_uuid": "767def80-e55f-4326-a4f8-71212813ae3f",
            "max_spendable": null,
            "total_spent": "0.00",
            "max_spendable_limit": null,
            "analytics": {},
            "shipping_method": null,
            "creating_client_id": "4-27304",
            "customer_id": "4-5MJI3G",
            "total_applied_deposits": "0.00",
            "escrow_transaction_record_id": null,
            "pickup_location": null,
            "request_shipping_quote": false,
            "location_country": null,
            "paid_fields_changed_date": null,
            "paid_fields_last_sync_date": null,
            "paid_is_synced": false,
            "row_id": "4-6GU8LL",
            "card_service": "stripe",
            "either_or": {
                "max_spendable": null,
                "max_quantity": null,
                "groups": []
            },
            "effective_max_spendable": null,
            "is_approved": false,
            "customer": {
                "created": "2022-04-05T07:31:17.869Z",
                "creating_client_id": "4-27304",
                "facebook_uid": null,
                "name": "**********",
                "facebook_email": null,
                "preferred_email": "**********",
                "login": "**********",
                "phone_number": "**********",
                "tenant_id": "4-J5SH",
                "override_tenant_id": null,
                "preferred_payment_method": null,
                "paddle": null,
                "approved_at": "2022-04-05T07:31:17.871Z",
                "reviewed_at": null,
                "credit_approved": null,
                "given_name": "WEMVULA HOLDINGS ",
                "family_name": "WEMVULA",
                "textsearch_index_column": "'hold':2 'wemvula':1,3",
                "integration_id": null,
                "is_external_record": false,
                "username_alias": null,
                "title": null,
                "fax_number": null,
                "external_account_number": null,
                "preferred_credit_card_id": null,
                "default_auction_max_spendable_limit": null,
                "default_auction_max_spendable": null,
                "last_updated": "2022-06-24T09:05:38.512Z",
                "phone_number_two": null,
                "notes": null,
                "source": null,
                "referrer_host": null,
                "referrer_path": null,
                "do_not_email": false,
                "auto_approve_auction_registrations": false,
                "custom_fields": {},
                "owner_alias": null,
                "opt_in_marketing": false,
                "show_address_summary_in_auction": true,
                "block_auction_registrations": false,
                "phone_number_country": null,
                "phone_number_local_number": null,
                "fax_number_country": null,
                "fax_number_local_number": null,
                "is_deleted": null,
                "date_of_birth": null,
                "nationality": null,
                "requires_auction_registration_document": true,
                "preferred_timezone": null,
                "is_kyc_uploaded": false,
                "is_only_integration_id": null,
                "paid_external_id": null,
                "paid_fields_changed_date": null,
                "paid_fields_last_sync_date": null,
                "paid_is_synced": false,
                "is_login_disabled": null,
                "deleted_at": null,
                "is_customer_delete_requested": null,
                "row_id": "4-5MJI3G",
                "role": "user",
                "created_at": "2022-04-05T07:31:17.875Z",
                "updated_at": "2022-04-05T08:21:52.444Z",
                "customer_id": "4-5MJI3G",
                "uuid": "767def80-e55f-4326-a4f8-71212813ae3f",
                "shipping_address_id": "4-5MJSHW",
                "addresses": [],
                "payment_methods": [],
                "cardcustomers": []
            }
        }

The request returns the correct data, however when parsing the data the properties with underscores return a NULL value.

How can I overcome this?

How is the class declared? Can it be that in C# "auction_id" is written as "AuctionId"? Which JSON serializer do you use? System.Text.Json or NewtonSoft.Json? - Markus