Skip to content

Commit

Permalink
Merge branch 'master' into latest-codegen-master
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym-stripe authored Oct 16, 2023
2 parents 6b9d50e + 940dd54 commit f189766
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ test {
events "passed", "skipped", "failed"
exceptionFormat "full"
}

systemProperty "stripe.disallowGlobalResponseGetterFallback", "true"
}

spotless {
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/com/stripe/net/ApiResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public void setResponseGetter(StripeResponseGetter srg) {

protected StripeResponseGetter getResponseGetter() {
if (this.responseGetter == null) {
throw new IllegalStateException(
"The StripeResponseGetter has not been set on this resource. "
+ "This should not happen and is likely a bug in the Stripe Java library. "
+ "Please open a github issue on https://github.com/stripe/stripe-java or contact "
+ "Stripe Support at https://support.stripe.com/contact/");
if (isGlobalFallbackDisallowed()) {
throw new IllegalStateException(
"The resource you're trying to use was deserialized without the use of ApiResource.GSON.\n"
+ "ApiResource.GSON contains type adapters that are important for correct deserialization and functioning of the resource.\n"
+ "To deserialize Events use Webhook.constructEvent, for other resources use ApiResource.GSON.fromJson(...)`");
}
return getGlobalResponseGetter();
}
return this.responseGetter;
}
Expand Down Expand Up @@ -145,4 +147,9 @@ public static <T extends HasId> ExpandableField<T> setExpandableFieldId(

return new ExpandableField<>(newId, currentObject.getExpanded());
}

private static boolean isGlobalFallbackDisallowed() {
return Objects.equals(
System.getProperty("stripe.disallowGlobalResponseGetterFallback"), "true");
}
}
5 changes: 4 additions & 1 deletion src/test/java/com/stripe/net/ApiResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public void testInternalDeserializeSetsResponseGetter() {
Charge charge = ApiResource.INTERNAL_GSON.fromJson(json, Charge.class);
IllegalStateException e =
assertThrows(IllegalStateException.class, () -> charge.update(new HashMap<>()));
assertTrue(e.getMessage().contains("contact Stripe Support"));
assertTrue(
e.getMessage()
.contains(
"The resource you're trying to use was deserialized without the use of ApiResource.GSON"));
}
}

0 comments on commit f189766

Please sign in to comment.