Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
refactor all usages of the
Gson
object to use a singleton instance - sparing costly initialization, which has resulted in major performance implications for our clients.this is a known optimization as
Gson
instances are stateless and thread-safe ("Gson instances are Thread-safe so you can reuse them freely across multiple threads" https://www.javadoc.io/doc/com.google.code.gson/gson/2.9.0/com.google.gson/com/google/gson/Gson.html)https://stackoverflow.com/questions/31432758/should-i-reuse-one-instance-of-gson-or-create-new-ones-on-demand
https://stackoverflow.com/questions/10380835/is-it-ok-to-use-gson-instance-as-a-static-field-in-a-model-bean-reuse
tests and lint pass.
in addition consolidated
fromJson
declarations to a single top level one inUtils
to avoid code redundancy.