stripe/stripe-java

The StripeResponseGetter has not been set on this resource

MustafaSmesem opened this issue ยท 9 comments

Describe the bug

In stripe java 23.7.0 when call event.getDataObjectDeserializer() I got this error message:
The StripeResponseGetter has not been set on this resource. This should not happen and is likely a bug in the Stripe Java library.

I have checked the event, it has data and deprecated method event.getData().getObject() is work and can get the object.

To Reproduce

  1. create webhook endpoint
  2. listen to webhook event
  3. call event.getDataObjectDeserializer()

Expected behavior

I should get deserialized object

Code snippets

@PostMapping("/stripe")
public ResponseEntity<ApiErrorResponse> stripeWebhookHandler(@RequestHeader("Stripe-Signature") String stripeSignature, @RequestBody Event event) {
            var object = event.getDataObjectDeserializer().getObject();
....
}

OS

macOS

Java version

Java 17

stripe-java version

v23.7.0

API version

2023-08-16

Additional context

No response

Hi @MustafaSmesem ! Thanks the bug report. I was able to reproduce your issue. I believe you can fix this by changing the type of the request body to a string in your handler's method signature, and using the library's builtin event parsing method:

@PostMapping("/stripe")
public ResponseEntity<ApiErrorResponse> stripeWebhookHandler(@RequestHeader("Stripe-Signature") String stripeSignature, @RequestBody **String payload**) {
        Event event = null;
        try {
          event = Webhook.constructEvent(payload, sigHeader, "{{WEBHOOK_SIGNING_SECRET}}");
        } catch (SignatureVerificationException e) {
          ...
        }
        var object = event.getDataObjectDeserializer().getObject();
....
}

I'm going to keep this issue open since this error message is misleading, and I don't think it should be thrown in this case.

yglodt commented

Can anyone tell the most recent version not suffering from this bug ?

I know for sure 23.2.0, but I would preferably upgrade to the lastest non-affected version.

The 23.4.0 is the last version before this bug was introduced. We'll ship a version with a fix early next week.

The v23.10.0 has the fix for this issue.

Hi @pakrym-stripe, I also noticed this happening in the newer v24.0.0 release. Should/can this fix also be ported/merged into the v24 release line?

@jasperroel can you share the error message you are getting please along with the stack trace?

That seems to have been user error around v24.0.0. But I'll share what I did see:

Working in v24.0.0

After rebuilding with v24.0.0, I don't see this scenario happen anymore.
You can see stripeObject being populated with the correct object.
image

Not yet working in v23.10.0

In v23.10.0 I do still see the error though?
You can see stripeObject now contains an Optional.empty instead of the object I was expecting.
image

There is no stacktrace or any warnings on my logger from Stripe that I can see.

I think the Object.empty() problem might be related to the API version switch between 23 and 24. If you webhook sends events using 2023-10-16 but the library is pinned to 2023-08-16 the EventDataObjectDeserializer will return Optional.empty.

Ah, interesting. I don't remember switching the API version, but it seems there is indeed a disconnect between what I'm using in production and test and the various libraries I'm using. Time to bump them all to the latest API :-).

Thanks for the help and suggestion, much appreciated!