{"action":"created","issue":{"url":"https://api.github.com/repos/stripe/stripe-java/issues/96","labels_url":"https://api.github.com/repos/stripe/stripe-java/issues/96/labels{/name}","comments_url":"https://api.github.com/repos/stripe/stripe-java/issues/96/comments","events_url":"https://api.github.com/repos/stripe/stripe-java/issues/96/events","html_url":"https://github.com/stripe/stripe-java/issues/96","id":40355909,"number":96,"title":"please add support for serializing Stripe objects back to JSON","user":{"login":"vitezg","id":745368,"avatar_url":"https://avatars.githubusercontent.com/u/745368?v=3","gravatar_id":"","url":"https://api.github.com/users/vitezg","html_url":"https://github.com/vitezg","followers_url":"https://api.github.com/users/vitezg/followers","following_url":"https://api.github.com/users/vitezg/following{/other_user}","gists_url":"https://api.github.com/users/vitezg/gists{/gist_id}","starred_url":"https://api.github.com/users/vitezg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitezg/subscriptions","organizations_url":"https://api.github.com/users/vitezg/orgs","repos_url":"https://api.github.com/users/vitezg/repos","events_url":"https://api.github.com/users/vitezg/events{/privacy}","received_events_url":"https://api.github.com/users/vitezg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-08-15T15:16:19Z","updated_at":"2015-02-26T16:18:03Z","closed_at":null,"body":"It would be great to have official support for serializing the Stripe object back to JSON format.\r\nThe use case is saving the objects to the disk for later processing / caching.\r\n\r\nSerializing and then deserializing almost works, however at least when deserializing an Event object EventDataDeserializer.java will throw a NullPointerException on line 105, because the data.object.object attribute does not get created. \r\n\r\nExample code:\r\n\r\nString json=APIResource.GSON.toJson(Event.retrieve(\"...\"));\r\n// the json string is now missing the data.object.object attribute, which \r\n// will result in an NPE\r\nEvent restored=APIResource.GSON.fromJson(json, Event.class);\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/stripe/stripe-java/issues/comments/76207574","html_url":"https://github.com/stripe/stripe-java/issues/96#issuecomment-76207574","issue_url":"https://api.github.com/repos/stripe/stripe-java/issues/96","id":76207574,"user":{"login":"nicksellen","id":31616,"avatar_url":"https://avatars.githubusercontent.com/u/31616?v=3","gravatar_id":"","url":"https://api.github.com/users/nicksellen","html_url":"https://github.com/nicksellen","followers_url":"https://api.github.com/users/nicksellen/followers","following_url":"https://api.github.com/users/nicksellen/following{/other_user}","gists_url":"https://api.github.com/users/nicksellen/gists{/gist_id}","starred_url":"https://api.github.com/users/nicksellen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicksellen/subscriptions","organizations_url":"https://api.github.com/users/nicksellen/orgs","repos_url":"https://api.github.com/users/nicksellen/repos","events_url":"https://api.github.com/users/nicksellen/events{/privacy}","received_events_url":"https://api.github.com/users/nicksellen/received_events","type":"User","site_admin":false},"created_at":"2015-02-26T16:18:03Z","updated_at":"2015-02-26T16:18:03Z","body":"I had a similar issue, \"source\" field inside a charge was being serialized as an empty object.\r\n\r\nI created my own GSON objects based on the stripe ones and so far it's working:\r\n\r\n    private static final Gson GSON_TO = new GsonBuilder()\r\n        .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)\r\n        .registerTypeAdapter(EventData.class, new EventDataDeserializer())\r\n        .registerTypeAdapter(ChargeRefundCollection.class, new ChargeRefundCollectionDeserializer())\r\n        .registerTypeAdapter(FeeRefundCollection.class, new FeeRefundCollectionDeserializer())\r\n        .registerTypeAdapter(StripeRawJsonObject.class, new StripeRawJsonObjectDeserializer())\r\n        .registerTypeAdapter(Dispute.class, new DisputeDataDeserializer())\r\n      .create();\r\n    \r\n    private static final Gson GSON_FROM = new GsonBuilder()\r\n        .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)\r\n        .registerTypeAdapter(EventData.class, new EventDataDeserializer())\r\n        .registerTypeAdapter(ChargeRefundCollection.class, new ChargeRefundCollectionDeserializer())\r\n        .registerTypeAdapter(FeeRefundCollection.class, new FeeRefundCollectionDeserializer())\r\n        .registerTypeAdapter(StripeRawJsonObject.class, new StripeRawJsonObjectDeserializer())\r\n        .registerTypeAdapter(Dispute.class, new DisputeDataDeserializer())\r\n        .registerTypeAdapter(PaymentSource.class, new PaymentSourceDeserializer())\r\n      .create();"}}