-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Mention in Gson Javadoc that reusing instance can improve performance
#2983
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,14 +47,16 @@ | |
| import java.util.concurrent.ConcurrentMap; | ||
|
|
||
| /** | ||
| * This is the main class for using Gson. Gson is typically used by first constructing a Gson | ||
| * instance and then invoking {@link #toJson(Object)} or {@link #fromJson(String, Class)} methods on | ||
| * it. Gson instances are Thread-safe so you can reuse them freely across multiple threads. | ||
| * This is the main class for using Gson. Gson is typically used by first constructing a {@code | ||
| * Gson} instance and then invoking {@link #toJson(Object)} or {@link #fromJson(String, Class)} | ||
| * methods on it. {@code Gson} instances are Thread-safe so you can reuse them freely across | ||
| * multiple threads. | ||
| * | ||
| * <p>You can create a Gson instance by invoking {@code new Gson()} if the default configuration is | ||
| * all you need. You can also use {@link GsonBuilder} to build a Gson instance with various | ||
| * configuration options such as versioning support, pretty printing, custom newline, custom indent, | ||
| * custom {@link JsonSerializer}s, {@link JsonDeserializer}s, and {@link InstanceCreator}s. | ||
| * <p>You can create a {@code Gson} instance by invoking {@link #Gson() new Gson()} if the default | ||
| * configuration is all you need. You can also use {@link GsonBuilder} to build a {@code Gson} | ||
| * instance with various configuration options such as versioning support, pretty printing, custom | ||
| * newline, custom indent, custom {@link JsonSerializer}s, {@link JsonDeserializer}s, and {@link | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps rewrite this last bit to talk about
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean mentioning them additionally, or instead of |
||
| * InstanceCreator}s. | ||
| * | ||
| * <p>Here is an example of how Gson is used for a simple Class: | ||
| * | ||
|
|
@@ -89,6 +91,11 @@ | |
| * <p>See the <a href="https://github.com/google/gson/blob/main/UserGuide.md">Gson User Guide</a> | ||
| * for a more complete set of examples. | ||
| * | ||
| * <p>When serializing or deserializing a type, {@code Gson} instances cache the type adapters they | ||
| * created for that type. It can therefore improve performance to reuse a single {@code Gson} | ||
| * instance (for example by storing it in a {@code static final} field), especially when relying on | ||
| * the built-in reflection-based adapter or when using custom type adapter factories. | ||
| * | ||
| * <h2 id="default-lenient">JSON Strictness handling</h2> | ||
| * | ||
| * For legacy reasons most of the {@code Gson} methods allow JSON data which does not comply with | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the distracting capitalization of "Thread-safe" while you are here?