Amazon-SP-API-CSharp
Amazon-SP-API-CSharp copied to clipboard
Newtonsoft.Json.JsonSerializationException when deserialing some Catalog Item images
Hello,
I'm having the following error when getting a Catalog Item (using CSharpAmazonSpAPI version 1.7.2, but the issue was already there in v1.6.x).
Newtonsoft.Json.JsonSerializationException: Error converting value "PT09" to type 'System.Nullable`1[FikaAmazonAPI.AmazonSpApiSDK.Models.CatalogItems.V20220401.ItemImage+VariantEnum]'. Path 'images[0].images[16].variant', line 1, position 2436.
Actually, it happens when requesting a catalog item, including images, and some of its image variants are not handled properly. For instance: "PT09", "PT10","SIDE", ...
The following code snippet reproduces the bug using Amazon's SPApi Sandbox:
var amazonConnection = new AmazonConnection(new AmazonCredential
{
// ...
Environment = Constants.Environments.Sandbox
});
// throws JsonSerializationException
var ci = await amazonConnection.CatalogItem.GetCatalogItem202204Async(new ParameterGetCatalogItem
{
ASIN = "B07N4M94X4",
marketplaceIds = new List<string> { "ATVPDKIKX0DER" },
includedData = new List<Constants.IncludedData>()
{
Constants.IncludedData.dimensions,
Constants.IncludedData.identifiers,
Constants.IncludedData.images,
Constants.IncludedData.productTypes,
Constants.IncludedData.relationships,
Constants.IncludedData.salesRanks,
Constants.IncludedData.summaries,
Constants.IncludedData.vendorDetails
}
});
And here is the complete stacktrace:
Newtonsoft.Json.JsonSerializationException: Error converting value "PT09" to type 'System.Nullable`1[FikaAmazonAPI.AmazonSpApiSDK.Models.CatalogItems.V20220401.ItemImage+VariantEnum]'. Path 'images[0].images[16].variant', line 1, position 2436.
---> System.ArgumentException: Requested value 'PT09' was not found.
at Newtonsoft.Json.Utilities.EnumUtils.ParseEnum(Type enumType, NamingStrategy namingStrategy, String value, Boolean disallowNumber)
at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
--- End of inner exception stack trace ---
at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
at FikaAmazonAPI.Services.RequestService.ExecuteRequestTry[T](RateLimitType rateLimitType, CancellationToken cancellationToken)
at FikaAmazonAPI.Services.RequestService.ExecuteRequestAsync[T](RateLimitType rateLimitType, CancellationToken cancellationToken)
at FikaAmazonAPI.Services.CatalogItemService.GetCatalogItem202204Async(ParameterGetCatalogItem parameterGetCatalogItem, CancellationToken cancellationToken)
Does anyone know how to fix this or have a workaround? Thanks in advance
Looks like one of the enumerate values doesn't exist. You could try to locate PT08 in library source code. Add in the missing values and push a PR.
Hi Andy, thanks for your reply. I finally had time to work on this fix and pushed #683