Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text '' could not be parsed at index 0 #291

Open
Jookus opened this issue Nov 13, 2022 · 3 comments
Open

Text '' could not be parsed at index 0 #291

Jookus opened this issue Nov 13, 2022 · 3 comments

Comments

@Jookus
Copy link

Jookus commented Nov 13, 2022

Since a few days I am getting the following error when using the FBA Inventory API with the Java sdk without specifying a startDateTime. If I set any startDateTime, everything is fine, but I need to go throw the whole inventory database and as far as I understood the documentation startDateTime should be optional for that purpose.

    java.time.format.DateTimeParseException: Text '' could not be parsed at index 0

	at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
	at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
	at java.time.OffsetDateTime.parse(OffsetDateTime.java:402)
	at com.amazon.sellingpartner.JSON$OffsetDateTimeTypeAdapter.read(JSON.java:215)
	at com.amazon.sellingpartner.JSON$OffsetDateTimeTypeAdapter.read(JSON.java:179)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
	at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
	at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
	at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
	at com.google.gson.Gson.fromJson(Gson.java:887)
	at com.google.gson.Gson.fromJson(Gson.java:852)
	at com.google.gson.Gson.fromJson(Gson.java:801)
	at com.amazon.sellingpartner.JSON.deserialize(JSON.java:137)
	at com.amazon.sellingpartner.ApiClient.deserialize(ApiClient.java:760)
	at com.amazon.sellingpartner.ApiClient.handleResponse(ApiClient.java:963)
	at com.amazon.sellingpartner.ApiClient.execute(ApiClient.java:890)
	at com.amazon.sellingpartner.api.FbaInventoryApi.getInventorySummariesWithHttpInfo(FbaInventoryApi.java:195)
	at com.amazon.sellingpartner.api.FbaInventoryApi.getInventorySummaries(FbaInventoryApi.java:175)

Update:
While digging deeper I found out, that I recently created a new catalog item that has not been updated yet.
Here is the raw response from the api:

     {
            "asin": "XXXXX",
            "fnSku": "XXXXX",
            "sellerSku": "XXXXX",
            "condition": "NewItem",
            "inventoryDetails": {"fulfillableQuantity":0,"inboundWorkingQuantity":0,"inboundShippedQuantity":0,"inboundReceivingQuantity":0,"reservedQuantity":{"totalReservedQuantity":0,"pendingCustomerOrderQuantity":0,"pendingTransshipmentQuantity":0,"fcProcessingQuantity":0},"researchingQuantity":{"totalResearchingQuantity":0,"researchingQuantityBreakdown":[]},"unfulfillableQuantity":{"totalUnfulfillableQuantity":0,"customerDamagedQuantity":0,"warehouseDamagedQuantity":0,"distributorDamagedQuantity":0,"carrierDamagedQuantity":0,"defectiveQuantity":0,"expiredQuantity":0},"futureSupplyQuantity":{"reservedFutureSupplyQuantity":0,"futureSupplyBuyableQuantity":0}},
            "lastUpdatedTime": "",  <------------------------------------ EMPTY STRING <-----------------
            "productName": "XXXXXXXXXXXXXXXXXXXXXXX",
            "totalQuantity": 0
        }

In this case 'lastUpdatedTime' is empty and causes the crash in ApiClient class when trying to deserialize to the GetInventorySummariesResponse class.
Other people have the same issue with different sdks: Link

I think the sdk should be able to handle these empty variables.

@Jookus
Copy link
Author

Jookus commented Nov 14, 2022

As a workaround in the java sdk you can find the OffsetDateTimeTypeAdapter in the generated JSON.java class and change the following function:

 @Override
        public OffsetDateTime read(JsonReader in) throws IOException {
            switch (in.peek()) {
                case NULL:
                    in.nextNull();
                    return null;
                default:
                    String date = in.nextString();
                    if (date.length() == 0) return null;  <------- this is new to skip empty values
                    if (date.endsWith("+0000")) {
                        date = date.substring(0, date.length()-5) + "Z";
                    }
                    return OffsetDateTime.parse(date, formatter);
            }
        }

@smargoli2
Copy link

@Jookus , thanks! The C# code is generated differently. I tried messing with the JsonSerializerSettings but there is no property for the JSON serializer to ignore null values when deserializing. I will try to submit a PR to OpenAPIGenerator (I am using that generator) to add such an option (i.e. GenerateOptionalPropertiesAsNullable).

@lvyuanj
Copy link

lvyuanj commented Apr 6, 2024

@Jookus, The reason for this problem is that when the response data is returned, the time field is an empty string, and the source code only handles null and non-empty times. No processing is done on time data that returns null characters. If is a Java SDK, find the corresponding JSON class, find the corresponding OffsetDateTimeTypeAdapter the read method to do the processing of an empty string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants