The CatalogObject API returns undocumented properties in the response payload under certain conditions (see Property default_unit_cost is not documented and is missing in .NET SDK - Questions)
I was assuming that those would be saved into the AdditionalProperties
collection on the response object as described in the .Net SDK documentation at GitHub - square/square-dotnet-sdk: .NET client library for the Square API :
Every response type includes the
AdditionalProperties
property, which returns anIDictionary<string, JsonElement>
that contains any properties in the JSON response that were not specified in the returned class. Similar to the use case for sending additional parameters, this can be useful for API features not present in the SDK yet.
…but I am not seeing the AdditionalProperties
collection being populated for such a request - it always comes back as an empty object.
Why is it not being populated with the unmapped properties in the CatalogObject API response payload JSON?
Does it require newer than System.Text.Json 8.0.5? Updated to latest, no change.
Or does it fail if the unmapped properties are on a sub-object, like on CatalogObject.ItemData.Variations
or CatalogObject.ItemVariationData
?
I tried feeding GetCatalogObjectResponse
JSON into System.Text.Json.Serialiaser.Deserialize<Square.GetCatalogObjectResponse>()
and it didn’t capture any of the unmapped properties at any level. Is this something broken in the system library?
Test JSON, lightly modified from raw API response containing production data to add extra unmapped properties:
string JSON = @"
{
""fnord_at_root"": ""FNORD!"",
""object"": {
""fnord_in_obj"": ""FNORD!"",
""type"": ""ITEM_VARIATION"",
""id"": ""G5Z2L2QE3AU6FQZNZSE2UH74"",
""updated_at"": ""2025-05-03T23:13:46.211Z"",
""created_at"": ""2020-02-09T23:57:43.516Z"",
""version"": 1746314026211,
""is_deleted"": false,
""catalog_v1_ids"": [
{
""catalog_v1_id"": ""11794D01-E4E6-46DA-B5E8-4888343D83D3"",
""location_id"": ""FE9PCJ73QSNQG""
}
],
""present_at_all_locations"": false,
""present_at_location_ids"": [
""FE9PCJ73QSNQG""
],
""item_variation_data"": {
""fnord_in_ivd"": ""FNORD!"",
""item_id"": ""DBJPHLW3G3TD4X3RTXGJWDQ4"",
""name"": ""Yellow Gold, Prong Set, 1.5mm"",
""sku"": ""DIAPY15"",
""ordinal"": 0,
""pricing_type"": ""FIXED_PRICING"",
""price_money"": {
""amount"": 13300,
""currency"": ""USD""
},
""location_overrides"": [
{
""location_id"": ""FE9PCJ73QSNQG"",
""track_inventory"": true,
""inventory_alert_type"": ""LOW_QUANTITY"",
""inventory_alert_threshold"": 2,
""sold_out"": true
}
],
""price_description"": """",
""item_option_values"": [
{
""item_option_id"": ""O4DLLS6TZHH753TZL5SDAEHH"",
""item_option_value_id"": ""Q4KNDL3273ZPJILPFQXDE4ZP""
},
{
""item_option_id"": ""PBI6U45GFIG3VRRKN75KFHOS"",
""item_option_value_id"": ""QKVOBDE5BLF6GTDSJRU3N3QK""
},
{
""item_option_id"": ""Z3FWJB5G4UMUDJVXFJO3K4GX"",
""item_option_value_id"": ""BXBMRYW2DGCRJWMFDXUIHPQT""
}
],
""sellable"": true,
""stockable"": true,
""default_unit_cost"": {
""amount"": 2676,
""currency"": ""USD""
},
""channels"": [
""CH_Bzzoj7miQci5WwGZ5daZ6ct6QDUEYFJabhhILQlQuYC""
],
""item_variation_vendor_info_ids"": [
""2A6L7G62YRAVXNVYANBKBWK3""
],
""item_variation_vendor_infos"": [
{
""type"": ""ITEM_VARIATION_VENDOR_INFO"",
""id"": ""2A6L7G62YRAVXNVYANBKBWK3"",
""updated_at"": ""2025-04-19T18:54:48.119Z"",
""created_at"": ""2020-03-07T02:09:30.16Z"",
""version"": 1745088888119,
""is_deleted"": false,
""present_at_all_locations"": false,
""present_at_location_ids"": [
""FE9PCJ73QSNQG""
],
""item_variation_vendor_info_data"": {
""ordinal"": 0,
""price_money"": {
""amount"": 2676,
""currency"": ""USD""
},
""item_variation_id"": ""G5Z2L2QE3AU6FQZNZSE2UH74"",
""vendor_id"": ""SDD5FWEBC4N4DB5Z""
}
}
]
}
}
}
";
var obj = System.Text.Json.JsonSerializer.Deserialize<GetCatalogObjectResponse>(JSON);
Opened issue at github: BUG: AdditionalProperties does not capture unmapped properties present in API response JSON payload · Issue #156 · square/square-dotnet-sdk