romixch / stripe-java-graalvm

GraalVM configuration files for using stripe-java in Quarkus or any oder App compiled with native-image.
GNU General Public License v3.0
8 stars 5 forks source link

Inner classes are not declared as reflective #1

Open omarkad2 opened 3 years ago

omarkad2 commented 3 years ago

I'm using quarkus on an application that uses Stripe library. So in order to declare all reflective classes used by Stripe I tried this solution. Yet when testing I get errors in my native image for each Stripe's inner class I try to deserialize.

jaurakunal commented 2 years ago

@omarkad2 I was able to make it work for an inner class using the following format

  {
    "name": "com.stripe.model.Class$InvoiceSettings",
    "allDeclaredFields": true,
    "allDeclaredMethods": true,
    "allPublicMethods": true,
    "allDeclaredConstructors": true,
    "methods": [
      {
        "name": "<init>",
        "parameterTypes": []
      }
    ]
  }

So use a $ between the top level class and the inner class instead of a . and things will work.

prashant-gupta-kune commented 8 months ago

How do you fix

java.lang.RuntimeException: Unable to create instance of class com.stripe.model.Customer. Registering an InstanceCreator or a TypeAdapter for this type, or adding a no-args constructor may fix this problem.

Given there are no - no-args constructor defined in stripe models.

izogfif commented 3 months ago

How do you fix

java.lang.RuntimeException: Unable to create instance of class com.stripe.model.Customer. Registering an InstanceCreator or a TypeAdapter for this type, or adding a no-args constructor may fix this problem.

Given there are no - no-args constructor defined in stripe models.

@prashant-gupta-kune I fixed a similar issue in Spring Boot by creating a @Configuration class with @RegisterReflectionForBinding annotation.

import com.stripe.model.StripeError;
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
import org.springframework.context.annotation.Configuration;

@Configuration
/*
 * RegisterReflectionForBinding fixes error "Unable to create instance of class
 * com.stripe.model.StripeError." and something about unsafeCall
 */
@RegisterReflectionForBinding(StripeError.class)
public class PaymentConfig {}

So if you check what @RegisterReflectionForBinding does, you might be able to fix it outside of Spring Boot app.