-
Notifications
You must be signed in to change notification settings - Fork 4
Added log on Event resource #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Fix: Event.log not populated on Event.query(), Event.page(), Event.get()ProblemWhen using Root CauseThe Interestingly, line 121 already uses the correct approach for case "payment-request":
return GsonEvent.getInstance().fromJson(jsonObject, PaymentRequestEvent.class);This same pattern should be applied to all other event types. RepositoryThis fix should be applied to sdk-java ( File: Code ChangesFROM (Current - Lines 73-129):public static class Deserializer implements JsonDeserializer<Event> {
@Override
public Event deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
JsonElement type = jsonObject.get("subscription");
if (type != null) {
switch (type.getAsString()) {
case "transfer":
return context.deserialize(jsonObject,
TransferEvent.class);
case "boleto":
return context.deserialize(jsonObject,
BoletoEvent.class);
case "boleto-payment":
return context.deserialize(jsonObject,
BoletoPaymentEvent.class);
case "utility-payment":
return context.deserialize(jsonObject,
UtilityPaymentEvent.class);
case "boleto-holmes":
return context.deserialize(jsonObject,
BoletoHolmesEvent.class);
case "invoice":
return context.deserialize(jsonObject,
InvoiceEvent.class);
case "deposit":
return context.deserialize(jsonObject,
DepositEvent.class);
case "brcode-payment":
return context.deserialize(jsonObject,
BrcodePaymentEvent.class);
case "tax-payment":
return context.deserialize(jsonObject,
TaxPaymentEvent.class);
case "darf-payment":
return context.deserialize(jsonObject,
DarfPaymentEvent.class);
case "invoice-pull-subscription":
return context.deserialize(jsonObject,
InvoicePullSubscriptionEvent.class);
case "invoice-pull-request":
return context.deserialize(jsonObject,
InvoicePullRequestEvent.class);
case "verified-account":
return context.deserialize(jsonObject,
VerifiedAccountEvent.class);
case "payment-request":
return GsonEvent.getInstance().fromJson(jsonObject, PaymentRequestEvent.class);
default:
return context.deserialize(jsonObject,
UnknownEvent.class);
}
}
return null;
}
}TO (Fixed):public static class Deserializer implements JsonDeserializer<Event> {
@Override
public Event deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
JsonElement type = jsonObject.get("subscription");
if (type != null) {
Gson gson = GsonEvent.getInstance();
switch (type.getAsString()) {
case "transfer":
return gson.fromJson(jsonObject, TransferEvent.class);
case "boleto":
return gson.fromJson(jsonObject, BoletoEvent.class);
case "boleto-payment":
return gson.fromJson(jsonObject, BoletoPaymentEvent.class);
case "utility-payment":
return gson.fromJson(jsonObject, UtilityPaymentEvent.class);
case "boleto-holmes":
return gson.fromJson(jsonObject, BoletoHolmesEvent.class);
case "invoice":
return gson.fromJson(jsonObject, InvoiceEvent.class);
case "deposit":
return gson.fromJson(jsonObject, DepositEvent.class);
case "brcode-payment":
return gson.fromJson(jsonObject, BrcodePaymentEvent.class);
case "tax-payment":
return gson.fromJson(jsonObject, TaxPaymentEvent.class);
case "darf-payment":
return gson.fromJson(jsonObject, DarfPaymentEvent.class);
case "invoice-pull-subscription":
return gson.fromJson(jsonObject, InvoicePullSubscriptionEvent.class);
case "invoice-pull-request":
return gson.fromJson(jsonObject, InvoicePullRequestEvent.class);
case "verified-account":
return gson.fromJson(jsonObject, VerifiedAccountEvent.class);
case "payment-request":
return gson.fromJson(jsonObject, PaymentRequestEvent.class);
default:
return gson.fromJson(jsonObject, UnknownEvent.class);
}
}
return null;
}
}Summary of Changes
Why This Fix Works
Comparison with PR #117PR #117 proposes adding a
Both approaches could be combined if desired, but this fix alone resolves the core issue while preserving the existing typed API. Expected Behavior After FixEvent.Page page = Event.page();
for (Event event : page.events) {
if (event instanceof Event.BoletoEvent) {
Event.BoletoEvent boletoEvent = (Event.BoletoEvent) event;
System.out.println(boletoEvent.log.type); // "paid"
System.out.println(boletoEvent.log.boleto.id); // "5384248229888000"
}
}Thank you for considering this fix. Please let me know if you have any questions or need further clarification. |
Added