crowdin-api-client-java icon indicating copy to clipboard operation
crowdin-api-client-java copied to clipboard

WebhookApi.listWebhooks() throws HttpException

Open Marzuh opened this issue 1 year ago • 2 comments

Actual: WebhookApi.listWebhooks() throws HttpException

Error message: HttpException.Error(code=null, message=Cannot deserialize value of type java.util.LinkedHashMap<java.lang.String,java.lang.String> from Array value (token JsonToken.START_ARRAY) at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 212] (through reference chain: com.crowdin.client.webhooks.model.WebhookResponseList["data"]->java.util.ArrayList[0]->com.crowdin.client.webhooks.model.WebhookResponseObject["data"]->com.crowdin.client.webhooks.model.Webhook["headers"]))

Expected: WebhookApi.listWebhooks() returns ResponseList<Webhook>

Up to me its looks loike mapping error. If I change in WebHookApi.java:45 WebhookResponseList webhookResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/webhooks", new HttpRequestConfig(queryParams), WebhookResponseList.class); to WebhookResponseList webhookResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/webhooks", new HttpRequestConfig(queryParams), Object.class); there is no exception threw.

Marzuh avatar Jul 12 '24 08:07 Marzuh

Screenshot 2024-07-12 at 11 47 10

Marzuh avatar Jul 12 '24 08:07 Marzuh

How to reproduce: Setup at least one webhook in crowndin without any headers. If all webhooks have not empty headers then no exception.

Marzuh avatar Jul 12 '24 10:07 Marzuh

After de5dfe77b969d81d94ee362df59be8a714d7d859 headers for new webhook can't be provided as array/list, so looks like the exception above is caused by deserialization of old data structure.

@Marzuh do you reproduce it on clean environment with the latest version of the library? @andrii-bodnar, does this need some backward compatibility solution for such cases (changes are already quite old)?

Besomhead avatar Oct 02 '24 14:10 Besomhead

@Besomhead I haven't released it yet, but yes, we should keep it backwards compatible. Isn't it backwards compatible?

andrii-bodnar avatar Oct 02 '24 18:10 andrii-bodnar

@Besomhead I haven't released it yet, but yes, we should keep it backwards compatible. Isn't it backwards compatible?

@andrii-bodnar I'm not sure how webhooks are stored and can only make assumptions about what happened in Marzuh's case. Looks like there could be situation when we try to read old webhooks that were created when old request code allowed to pass headers as list of strings (general object prior to that). So, it could probably be resolved with simple DB/storage migration, like removing or updating webhooks with invalid headers, or we can create temporary code that should be removed in the next release, it could catch this particular mapping exception and convert headers to correct representation when constructing response object.

Besomhead avatar Oct 02 '24 20:10 Besomhead

@Besomhead not sure if I understood you correctly, the API only accepts and returns the event types that are listed in the docs - Add Webhook.

andrii-bodnar avatar Oct 03 '24 07:10 andrii-bodnar