Gson 2.11.0 #2677
eamonnmcmanus
announced in
Announcements
Gson 2.11.0
#2677
Replies: 1 comment 1 reply
-
@eamonnmcmanus, maybe it would be good to rename the title of this discussion, and the title of the GitHub release from "gson-parent-2.11.0" to "Gson 2.11.0" or similar?
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Most important changes
If you are using ProGuard or R8 (for example for Android projects) you might not need any special Gson configuration anymore if your classes have a no-args constructor and use
@SerializedName
for their fields.Strictness
API (@marten-voorberg & fellow students, Strict mode for JSON parsing, contributed by @marten-voorberg. #2437)Some of Gson's API is still lenient by default, but you can now use the newly added methods
GsonBuilder#setStrictness
,JsonReader#setStrictness
andJsonWriter#setStrictness
withStrictness.STRICT
to override this behavior and to instead strictly adhere to the JSON specification when parsing.FormattingStyle
class to allow configuring line breaks in JSON output (@mihnita, Fixes #776: Add settings for the kind of newline to use #2231)Can be set using
GsonBuilder#setFormattingStyle
andJsonWriter#setFormattingStyle
.TypeToken
can no longer capture type variables by default (@Marcono1234, PreventTypeToken
from capturing type variables #2376)This was previously a common source of issues. The newly thrown exception refers to a Troubleshooting Guide article which explains this in more detail and provides suggestions for updating affected code.
This affects for example
List
implementations returned by libraries such as Guava which are implemented as anonymous class, which were previously serialized asnull
. Anonymous and local classes without custom adapter will still be serialized asnull
.com.google.errorprone:error_prone_annotations
This dependency can be considered optional, but if missing it might lead to compiler warnings. Therefore Gson does not declare it as optional.
Feedback regarding the Troubleshooting Guide is appreciated!
JsonElement#toString
produces JSON output (@Marcono1234, Guarantee thatJsonElement.toString()
produces JSON #2659)Other changes
Bug fixes
JsonPrimitive#equals
results for largeBigInteger
values (@MaicolAntali, Fix theequals
method ofJsonPrimitive
to work withBigInteger
#2311)JsonPrimitive#equals
results for largeBigDecimal
values (@MaicolAntali, Adds support toBigDecimal
inJsonPrimitive#equals
#2364)JsonReader
throwingNumberFormatException
instead ofMalformedJsonException
for malformed Unicode escape sequences (@MaicolAntali, Fix #2334 #2337)TypeToken#getParameterized
returning bogusParameterizedType
for non-generic types (@Marcono1234, Support non-generic type forTypeToken.getParameterized
for legacy reasons #2447)RecordComponent
viaClass.forName
. #2465)JsonWriter#name
not throwing exception when no JSON object is currently being written (@shivam-sehgal, Changes to ensure if no object is opened user won't be able to write property name #2475; @Marcono1234, Throw exception when callingJsonWriter.name
outside JSON object #2476)Gson#getDelegateAdapter
not working properly for@JsonAdapter
(@Marcono1234, FixGson.getDelegateAdapter
not working properly forJsonAdapter
#2435)Note that
null
is now not allowed asskipPast
value anymore, which was previously allowed but undocumented.GsonBuilder
not rejecting type adapters forObject
andJsonElement
, whose default adapters cannot be overridden (@sachinp97; issue#2436: Throw exception when registering adapter for Object or JsonElement #2479)BigDecimal
andBigInteger
(@Marcono1234, Add limits when deserializingBigDecimal
andBigInteger
#2510)The new limits prevent potential performance problems when user code uses the deserialized numbers. Gson itself was and is not affected by these performance problems. The limits should be high enough to not cause issues for most use cases, but feedback is appreciated.
GsonBuilder#setDateFormat
not rejecting invalid date formats (@Carpe-Wang, validating the date format, add test case, since NumberFormatExceptio… #2538)GsonBuilder#setDateFormat
not rejecting invalid date styles (@Marcono1234, ValidateGsonBuilder.setDateFormat
style arguments & extend tests #2545)GsonBuilder#setDateFormat
ignoring partial DEFAULT style (@Marcono1234, FixGsonBuilder.setDateFormat
ignoring partial DEFAULT; deprecatesetDateFormat(int)
#2556)TypeToken#isAssignableFrom
throwingAssertionError
in some cases (@Marcono1234, Perform minor code clean-up #2544)TypeToken#equals
erroneously returningfalse
for equal generic type parameters in some cases (@d-william, Fix $Gson$Types equals method for TypeVariable when its generic declaration is not a Class #2599)pom.xml
(@Marcono1234, Fix incorrect inherited URLs inpom.xml
#2351)Performance improvements
BoundField
instance per field inReflectiveTypeAdapterFactory
#2440)ToNumberPolicy#LONG_OR_DOUBLE
(@ctasada, Improved Long-Double Number Policy #2674)Gson maintenance
com.google.gson
of the modulegson
#2299, Port all Junit assert to Truth asserts #2304)maven-compiler-plugin
#2308)spotless
plugin #2537)DateTypeAdapter
class to reduce code duplication (@Marcono1234, RemoveDateTypeAdapter
to avoid code duplication #2546)GitHub repository
master
tomain
For questions, ideas, tips...
Other
@CanIgnoreReturnValue
as appropriate to Gson methods (@eamonnmcmanus, Add@CanIgnoreReturnValue
as appropriate to Gson methods. #2369)This is useful if you enable Error Prone's
CheckReturnValue
in your project when compiling, however Gson itself does not enable this by default.Many thanks to @Marcono1234 for drafting these release notes.
This discussion was created from the release gson-parent-2.11.0.
Beta Was this translation helpful? Give feedback.
All reactions