You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the report and for the hints on how this could be improved!
It looks like it is possible to even move the complete creation of the BoundField outside the loop, so you only have one BoundField per field (regardless of whether @SerializedName is used or not), see #2440.
Instanciante a new JsonSerializer only for the main name, because created one can be an heavy operation.
As workaround you can specify a custom InstanceCreator which returns an existing instance of the serializer (respectively a singleton instance), for example:
Gsongson = newGsonBuilder()
.registerTypeAdapter(MySerializer.class, (InstanceCreator<?>) t -> MySerializer.INSTANCE)
.create();
It appears this is unfortunately not properly documented yet, see also #2442.
Gson version
2.10.1
Java / Android version
Java 17
Used tools
Description
When a class has a field with :
Then a new JsonSerializer will instanciate for each alternate names, even if they will never be used (serialize is always false because of this)
Expected behavior
Instanciante a new JsonSerializer only for the main name, because created one can be an heavy operation.
Actual behavior
A new JsonSerializer will instanciate for each alternate names
Reproduction steps
Run the following code
Dev hint
Maybe we can give
serialize
value to this method call and used it in some way ?OR
Create this type adapter before here
The text was updated successfully, but these errors were encountered: