Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.google.gson.JsonPrimitive.getAsString()" because the return value of "com.google.gson.JsonObject.getAsJsonPrimitive(String)" is null
at com.stripe.model.PaymentSourceTypeAdapterFactory$1.read(PaymentSourceTypeAdapterFactory.java:50)
at com.stripe.model.PaymentSourceTypeAdapterFactory$1.read(PaymentSourceTypeAdapterFactory.java:40)
at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:204)
at com.google.gson.Gson.fromJson(Gson.java:1227)
at com.google.gson.Gson.fromJson(Gson.java:1329)
at com.google.gson.Gson.fromJson(Gson.java:1300)
at com.google.gson.internal.bind.TreeTypeAdapter$GsonContextImpl.deserialize(TreeTypeAdapter.java:179)
at com.stripe.model.ExpandableFieldDeserializer.deserialize(ExpandableFieldDeserializer.java:47)
at com.stripe.model.ExpandableFieldDeserializer.deserialize(ExpandableFieldDeserializer.java:12)
at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:76)
at com.stripe.net.StripeCollectionItemTypeSettingFactory$1.read(StripeCollectionItemTypeSettingFactory.java:25)
at com.stripe.net.StripeResponseGetterSettingTypeAdapterFactory$1.read(StripeResponseGetterSettingTypeAdapterFactory.java:26)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.readIntoField(ReflectiveTypeAdapterFactory.java:212)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:433)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:393)
at com.stripe.net.StripeCollectionItemTypeSettingFactory$1.read(StripeCollectionItemTypeSettingFactory.java:25)
at com.stripe.net.StripeResponseGetterSettingTypeAdapterFactory$1.read(StripeResponseGetterSettingTypeAdapterFactory.java:26)
at com.google.gson.Gson.fromJson(Gson.java:1227)
at com.google.gson.Gson.fromJson(Gson.java:1137)
at com.google.gson.Gson.fromJson(Gson.java:1047)
at com.google.gson.Gson.fromJson(Gson.java:982)
at com.stripe.main.StripeClient.main(StripeClient.java:37)
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.google.gson.JsonPrimitive.getAsString()" because the return value of "com.google.gson.JsonObject.getAsJsonPrimitive(String)" is null
at com.stripe.model.PaymentSourceTypeAdapterFactory$1.read(PaymentSourceTypeAdapterFactory.java:50)
at com.stripe.model.PaymentSourceTypeAdapterFactory$1.read(PaymentSourceTypeAdapterFactory.java:40)
at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:204)
at com.google.gson.Gson.fromJson(Gson.java:1227)
at com.google.gson.Gson.fromJson(Gson.java:1329)
at com.google.gson.Gson.fromJson(Gson.java:1300)
at com.google.gson.internal.bind.TreeTypeAdapter$GsonContextImpl.deserialize(TreeTypeAdapter.java:179)
at com.stripe.model.ExpandableFieldDeserializer.deserialize(ExpandableFieldDeserializer.java:47)
at com.stripe.model.ExpandableFieldDeserializer.deserialize(ExpandableFieldDeserializer.java:12)
at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:76)
at com.stripe.net.StripeCollectionItemTypeSettingFactory$1.read(StripeCollectionItemTypeSettingFactory.java:25)
at com.stripe.net.StripeResponseGetterSettingTypeAdapterFactory$1.read(StripeResponseGetterSettingTypeAdapterFactory.java:26)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.readIntoField(ReflectiveTypeAdapterFactory.java:212)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:433)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:393)
at com.stripe.net.StripeCollectionItemTypeSettingFactory$1.read(StripeCollectionItemTypeSettingFactory.java:25)
at com.stripe.net.StripeResponseGetterSettingTypeAdapterFactory$1.read(StripeResponseGetterSettingTypeAdapterFactory.java:26)
at com.google.gson.Gson.fromJson(Gson.java:1227)
at com.google.gson.Gson.fromJson(Gson.java:1137)
at com.google.gson.Gson.fromJson(Gson.java:1047)
at com.google.gson.Gson.fromJson(Gson.java:982)
at com.stripe.main.StripeClient.main(StripeClient.java:37)
Expected behavior
the json should be able to generate subscription model class again
Code snippets
//Subscription Id used below has default_source not null and has value
String json = ApiResource.GSON.toJson(Subscription.retrieve("sub_1QL3OEFMxpe1bhsdExkQGaSA"));
System.out.println(json);
// This line breaks if the subscription has default_source: example value : "default_source": {
// "id": "card_1QL3OAFMxpe1bhsdof3pn97j"
// }
Subscription subs = ApiResource.GSON.fromJson(json, Subscription.class);
System.out.println(subs);
Hi @sashubelt , thanks for reporting! We've added this to our backlog and will take a look. Is this actively blocking functionality for you? Or have you been able to work around it?
Describe the bug
Generate JSON from to jeson method
Now create the model from generated json :
If the Json generated has following data the fromJson method breaks at this com.stripe.model.PaymentSourceTypeAdapterFactory line 50:
Generated Example Json :
Exception Stack Trace:
To Reproduce
Generate JSON from to jeson method
Now create the model from generated json :
If the Json generated has following data the fromJson method breaks at this com.stripe.model.PaymentSourceTypeAdapterFactory line 50:
Generated Example Json :
Exception Stack Trace:
Expected behavior
the json should be able to generate subscription model class again
Code snippets
OS
macOS
Java version
Java21
stripe-java version
v28.0.1
API version
2024-10-28.acacia
Additional context
No response