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
Use a single Gson instance #28
Comments
Hi Kilink, We use different Gson instance for each class because the Gson parsing settings might be different for different classes. Although it is not happening right now, we want to keep the flexibility for the future. If you've got performance hit because of this, please let us know so that we can try to find a solution. |
It confers other benefits apart from performance. Currently I can't customize the Gson instance whatsoever (e.g., to turn on pretty printing). The Gson instance could still be moved to APIContext, and when the need for a customized instance for a specific type arises, then you could handle it either using the current approach in that specific place, or via a factory method on the context (maybe by exposing the GsonBuilder?). As I mentioned in another issue, I will open a PR for this if you guys agree that it's a good idea. |
Additionally, I think any class/type-specific behavior can be achieved with type adapters or custom serializers/deserializers, while still maintaining the single Gson instance. |
It looks like all of the objects in com.facebook.ads.sdk.* have the same static, synchronized method for constructing the Gson object:
Gson instances are threadsafe, and therefore a single instance could be shared throughout the codebase. Maybe the APIContext can grow a method for getting the Gson instance? It would also make it easier for consumers to override the defaults.
The text was updated successfully, but these errors were encountered: