StripeClient#subscriptions().list() causes class com.google.gson.internal.LinkedTreeMap cannot be cast to class com.stripe.model.HasId
oabcd3s opened this issue · 5 comments
oabcd3s commented
Describe the bug
The following code throws an exception.
for (final Subscription subscription : stripeClient.subscriptions().list(params).autoPagingIterable()) {
System.out.println("subscription: " + subscription);
}
The exception is:
Exception in thread "main" java.lang.RuntimeException: Unable to lazy-load stripe objects
at com.stripe.model.PagingIterator.next(PagingIterator.java:57)
at com.stripe.model.PagingIterator.next(PagingIterator.java:9)
at SubscriptionsFailJavaMain.main(SubscriptionsFailJavaMain.java:32)
Caused by: java.lang.ClassCastException: class com.google.gson.internal.LinkedTreeMap cannot be cast to class com.stripe.model.HasId (com.google.gson.internal.LinkedTreeMap and com.stripe.model.HasId are in unnamed module of loader 'app')
at com.stripe.model.StripeCollection.setResponseGetter(StripeCollection.java:92)
at com.stripe.model.StripeObject.deserializeStripeObject(StripeObject.java:131)
at com.stripe.net.LiveStripeResponseGetter.request(LiveStripeResponseGetter.java:72)
at com.stripe.model.PagingIterator.list(PagingIterator.java:79)
at com.stripe.model.PagingIterator.next(PagingIterator.java:53)
... 2 more
To Reproduce
Here is a whole code to reproduce.
// The public API key
final String API_KEY = "sk_test_<redacted>";
final RequestOptions requestOptions = RequestOptions.builder().setApiKey(API_KEY).build();
final StripeClient stripeClient = new StripeClient(API_KEY);
final SubscriptionListParams params = SubscriptionListParams.builder()
.setLimit(100L)
.setCreated(
SubscriptionListParams.Created.builder()
.setGt(Instant.now().getEpochSecond() - 3 * 86400 /* 3 days */)
.build()
).build();
// // Works!
// for (final Subscription subscription : Subscription.list(params, requestOptions).autoPagingIterable()) {
// System.out.println("subscription: " + subscription);
// }
// Not works :(
for (final Subscription subscription : stripeClient.subscriptions().list(params).autoPagingIterable()) {
System.out.println("subscription: " + subscription);
}
Expected behavior
List subscriptions without errors.
Code snippets
No response
OS
macOS
Java version
corretto-11.0.16.1
stripe-java version
23.6.0
API version
23.6.0
Additional context
No response
richardm-stripe commented
Hello @oabcd3s, thank you so much for the report. I've been able to reproduce the error and a fix should be forthcoming.
oabcd3s commented
Hi @richardm-stripe, thank you for not only reproducing the error but also for the quick fix in the pull request. Really appreciate your swift action.
vojkny commented
https://github.com/stripe/stripe-java/blob/v23.9.0-beta.1/CHANGELOG.md
I understand this was not yet released?
pakrym-stripe commented
This fix should be in the v23.9.0-beta.1. Please let us know if you still see the issue.