Releases: google/gson
Gson 2.11.0
Most important changes
- Added default ProGuard / R8 rules (@Marcono1234, #2397, #2420; @sgjesse, #2448; @sfreilich)
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. - On Android, Gson now requires API level 21 or newer
- Added new
Strictness
API (@marten-voorberg & fellow students, #2437)
Some of Gson's API is still lenient by default, but you can now use the newly added methodsGsonBuilder#setStrictness
,JsonReader#setStrictness
andJsonWriter#setStrictness
withStrictness.STRICT
to override this behavior and to instead strictly adhere to the JSON specification when parsing. - New
FormattingStyle
class to allow configuring line breaks in JSON output (@mihnita, #2231)
Can be set usingGsonBuilder#setFormattingStyle
andJsonWriter#setFormattingStyle
. TypeToken
can no longer capture type variables by default (@Marcono1234, #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.- Added serialization support for anonymous and local classes with a custom adapter (@Marcono1234, #2498)
This affects for exampleList
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
. - Added dependency on
com.google.errorprone:error_prone_annotations
Your project can use Maven or Gradle dependency exclusions to remove the transitive error_prone_annotations dependency from Gson. Or if you are manually maintaining dependencies as JARs in your project you can omit error_prone_annotations. And it should still work correctly.
But Gson itself does declare it as a required dependency, and if you don't perform any custom configuration, then Maven or Gradle will by default try to download and use it. - Many exception messages now refer to the Troubleshooting Guide (@Marcono1234, #2357)
Feedback regarding the Troubleshooting Guide is appreciated! - Officially documented that JVM languages other than Java might not be fully supported, see the README.
- Guarantee that
JsonElement#toString
produces JSON output (@Marcono1234, #2659)
Other changes
Bug fixes
- Fixed incorrect
JsonPrimitive#equals
results for largeBigInteger
values (@MaicolAntali, #2311) - Fixed incorrect
JsonPrimitive#equals
results for largeBigDecimal
values (@MaicolAntali, #2364) - Fixed
JsonReader
throwingNumberFormatException
instead ofMalformedJsonException
for malformed Unicode escape sequences (@MaicolAntali, #2337) - Fixed
TypeToken#getParameterized
returning bogusParameterizedType
for non-generic types (@Marcono1234, #2447) - Fixed Java Record adapter not working for GraalVM Native Image (@eamonnmcmanus, #2465)
- Fixed
JsonWriter#name
not throwing exception when no JSON object is currently being written (@shivam-sehgal, #2475; @Marcono1234, #2476) - Fixed
Gson#getDelegateAdapter
not working properly for@JsonAdapter
(@Marcono1234, #2435)
Note thatnull
is now not allowed asskipPast
value anymore, which was previously allowed but undocumented. - Fixed
GsonBuilder
not rejecting type adapters forObject
andJsonElement
, whose default adapters cannot be overridden (@sachinp97; #2479) - Fixed no limits being enforced when deserializing
BigDecimal
andBigInteger
(@Marcono1234, #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. - Fixed
GsonBuilder#setDateFormat
not rejecting invalid date formats (@Carpe-Wang, #2538) - Fixed
GsonBuilder#setDateFormat
not rejecting invalid date styles (@Marcono1234, #2545) - Fixed
GsonBuilder#setDateFormat
ignoring partial DEFAULT style (@Marcono1234, #2556) - Fixed
TypeToken#isAssignableFrom
throwingAssertionError
in some cases (@Marcono1234, #2544) - Fixed date adapters not restoring time zone after parsing (@Carpe-Wang, #2549)
- Fixed
TypeToken#equals
erroneously returningfalse
for equal generic type parameters in some cases (@d-william, #2599) - Fixed incorrect inherited URLs in
pom.xml
(@Marcono1234, #2351)
Performance improvements
- Slightly reduce memory usage for reflection-based adapter (@sembseth, #2325; @Marcono1234, #2440)
- Improved parsing speed of
ToNumberPolicy#LONG_OR_DOUBLE
(@ctasada, #2674)
Gson maintenance
- Changed many unit tests to use Truth instead of JUnit for assertions (@MaicolAntali, #2299, #2304)
- Configured Error Prone to automatically check for bugs when compiling (@MaicolAntali, #2308)
- Simplified expected exception handling in tests (@elevne, #2454)
- Added integration test for GraalVM Native Image (@Marcono1234, #2466)
- Formatted the code according to the Google Style Guide & configured Spotless (@MaicolAntali, #2531, #2537)
- Made Maven build reproducible (@Marcono1234, #2543)
- Removed internal
DateTypeAdapter
class to reduce code duplication (@Marcono1234, #2546) - Dependencies and plugins updated by Dependabot
GitHub repository
- Renamed default branch from
master
tomain
- GitHub Discussions have been enabled
For questions, ideas, tips... - Added GitHub pull request template (@Marcono1234, #2326)
- Added check for Android API compatibility (@Marcono1234, #2431)
Other
- Added
@CanIgnoreReturnValue
as appropriate to Gson methods (@eamonnmcmanus, #2369)
This is useful if you enable Error Prone'sCheckReturnValue
in your project when compiling, however Gson itself does not enable this by default. - Various documentation and test improvements and typo fixes (@False-Mask; @avimathur009; @elevne; @0o001; @Codegass; @33nya)
Many thanks to @Marcono1234 for drafting these release notes.
Gson 2.10.1
This is technically a minor release rather than a patch release because there is one small API change: a new JsonObject.isEmpty()
method.
What's Changed: User-Visible Changes
- Added JsonObject method isEmpty() by @dhoard in #2233
- Fix non-threadsafe creation of adapter for type with cyclic dependency by @Marcono1234 in #1832
- Remove EOFException special casing of JsonStreamParser.next() by @Marcono1234 in #2281
- Improve exception message for duplicate field names by @Marcono1234 in #2251
- Fix the javadoc of JsonDeserializer.deserialize() by @MaicolAntali in #2243
- Bump os-maven-plugin from 1.7.0 to 1.7.1 by @dependabot in #2235
- Bump jackson-databind from 2.13.4.2 to 2.14.0 by @dependabot in #2234
- Bump maven-release-plugin from 3.0.0-M6 to 3.0.0-M7 by @dependabot in #2232
- Bump japicmp-maven-plugin from 0.16.0 to 0.17.1 by @dependabot in #2238
- Bump jackson-databind from 2.14.0 to 2.14.1 by @dependabot in #2241
- Bump bnd-maven-plugin from 6.3.1 to 6.4.0 by @dependabot in #2245
Site Documentation and Maintenance Changes (these were already visible)
- Add troubleshooting guide by @Marcono1234 in #2285
- Replace custom user guide header anchors by @Marcono1234 in #2289
- Improve variable names in user guide by @Marcono1234 in #2290
- Add 2.10 changes to CHANGELOG; minor release follow-ups by @Marcono1234 in #2229
- Mention in CHANGELOG that GitHub Releases are used in the future by @Marcono1234 in #2230
- GitHub Workflows security hardening by @sashashura in #2274
Other Changes
- Making consistent prefixs in PerformanceTest by @CirQ in #1760
- Adjust version numbers and a test to conform to the SemVer spec. by @eamonnmcmanus in #2237
- Remove covered condition in JsonNull.equals() by @MaicolAntali in #2271
- Remove the
final
keyword fromprivate
method by @MaicolAntali in #2276 - Code cleanup by @MaicolAntali in #2282
- Unnecessary unboxing at JsonPrimitive.getAsBoolean() by @MaicolAntali in #2277
- Rewrite the
testParsingDatesFormattedWithSystemLocale()
, Fix #2199 by @MaicolAntali in #2287 - Port tests from JUnit 3 to JUnit 4 by @MaicolAntali in #2294
New Contributors (thanks!)
- @CirQ made their first contribution in #1760
- @dhoard made their first contribution in #2233
- @MaicolAntali made their first contribution in #2243
- @sashashura made their first contribution in #2274
Full Changelog: gson-parent-2.10...gson-parent-2.10.1
Gson 2.10
Most important changes
-
Support for serializing and deserializing Java records, on Java ≥ 16. (#2201)
-
Add
JsonArray.asList
andJsonObject.asMap
view methods (#2225) -
Fix
TypeAdapterRuntimeTypeWrapper
not detecting reflectiveTreeTypeAdapter
andFutureTypeAdapter
(#1787) -
Improve
JsonReader.skipValue()
(#2062) -
Perform numeric conversion for primitive numeric type adapters (#2158)
-
Add
Gson.fromJson(..., TypeToken)
overloads (#1700) -
Fix changes to
GsonBuilder
affecting existingGson
instances (#1815) -
Make
JsonElement
conversion methods more consistent and fix javadoc (#2178) -
Throw
UnsupportedOperationException
whenJsonWriter.jsonValue
is not supported (#1651) -
Disallow
JsonObject
Entry.setValue(null)
(#2167) -
Fix
TypeAdapter.toJson
throwing AssertionError for custom IOException (#2172) -
Convert null to JsonNull for
JsonArray.set
(#2170) -
Fixed nullSafe usage. (#1555)
-
Validate
TypeToken.getParameterized
arguments (#2166) -
Fix #1702: Gson.toJson creates CharSequence which does not implement toString (#1703)
-
Prefer existing adapter for concurrent
Gson.getAdapter
calls (#2153) -
Improve
ArrayTypeAdapter
forObject[]
(#1716) -
Improve
AppendableWriter
performance (#1706)
List of all changes
- Improve AppendableWriter performance by @Marcono1234 in #1706
- Improve ArrayTypeAdapter for Object[] by @Marcono1234 in #1716
- Prefer existing adapter for concurrent
Gson.getAdapter
calls by @Marcono1234 in #2153 - Fix #1702: Gson.toJson creates CharSequence which does not implement toString by @Marcono1234 in #1703
- Deprecate JsonElement constructor by @Marcono1234 in #1761
- Validate
TypeToken.getParameterized
arguments by @Marcono1234 in #2166 - Fixed nullSafe usage. by @bufistov in #1555
- Convert null to JsonNull for
JsonArray.set
by @Marcono1234 in #2170 - Clarify that
GsonBuilder.setExclusionStrategies
does not replace existing ones by @Marcono1234 in #2168 - Fix typo by @JamesZBL in #1246
- Remove not needed .gitattributes file by @Marcono1234 in #1862
- Improve InternationalizationTest by @Marcono1234 in #1705
- Fix JsonWriter documentation regarding top-level value by @Marcono1234 in #1766
- Fix JsonTreeReader throwing wrong exception type for non-finite doubles by @Marcono1234 in #1782
- Clarify doc about non-finite numbers for non-lenient JsonReader by @Marcono1234 in #1723
- Fix
TypeAdapter.toJson
throwing AssertionError for custom IOException by @Marcono1234 in #2172 - Add test for JsonArray.isEmpty() by @LorenzNickel in #2173
- Disallow
JsonObject
Entry.setValue(null)
by @Marcono1234 in #2167 - Improve GsonTest.testGetAdapter_Concurrency by @Marcono1234 in #2177
- Add null checks for GsonBuilder methods by @Marcono1234 in #2179
- Throw UnsupportedOperationException when JsonWriter.jsonValue is not supported by @Marcono1234 in #1651
- Make JsonElement conversion methods more consistent and fix javadoc by @Marcono1234 in #2178
- Bump maven-javadoc-plugin from 3.4.0 to 3.4.1 by @dependabot in #2175
- Add tests checking GsonBuilder not affecting existing Gson instances by @Marcono1234 in #1815
- Fix #1697: Mention that GsonBuilder.registerTypeAdapter makes (de-)serializers null-safe by @Marcono1234 in #1704
- Replace
$Gson$Preconditions.checkNotNull
withObjects.requireNonNull
by @Marcono1234 in #2180 - Verify that JsonTreeReader and JsonTreeWriter override all methods by @Marcono1234 in #2181
- Fail Maven build on compiler warnings; remove some warning suppressions by @Marcono1234 in #2183
- Add GitHub workflow for checking API compatibility by @Marcono1234 in #2182
- Bump japicmp-maven-plugin from 0.15.7 to 0.16.0 by @dependabot in #2187
- Bump jackson-databind from 2.13.3 to 2.13.4 by @dependabot in #2191
- Remove usage of oss-parent Maven parent and update
ReleaseProcess.md
by @Marcono1234 in #2159 - Improve documentation by @Marcono1234 in #2193
- updated JsonDeserializer example by @deeptimarrivada1 in #2192
- Add Gson.fromJson(..., TypeToken) overloads by @Marcono1234 in #1700
- Bump maven-jar-plugin from 3.2.2 to 3.3.0 by @dependabot in #2195
- Build on JDK 17 as well as 11. by @eamonnmcmanus in #2198
- Fix incorrect HTML headings in Javadoc by @Marcono1234 in #2200
- Add a currently-failing test for Java records and
@Ignore
it. by @eamonnmcmanus in #2203 - Follow-up for record test build changes by @Marcono1234 in #2207
- Disable Maven transfer progress for GitHub workflows by @Marcono1234 in #2206
- Only create one UnsafeAllocator instance by @kb-1000 in #2196
- Mention in User Guide alternative for Gson versions without fromJson(..., TypeToken) by @Marcono1234 in #2209
- Fix typo in GsonBuilder Javadoc by @BillyGalbreath in #2213
- Add Javadoc
@since
tags for previously added elements by @Marcono1234 in #2211 - Improve versioning support documentation and validate version by @Marcono1234 in #2214
- Perform numeric conversion for primitive numeric type adapters by @Marcono1234 in #2158
- Clarify in documentation that Gson might cache strategy results by @Marcono1234 in #2215
- Improve
JsonReader.skipValue()
by @Marcono1234 in #2062 - Fix TypeAdapterRuntimeTypeWrapper not detecting reflective TreeTypeAdapter and FutureTypeAdapter by @Marcono1234 in #1787
- Support Java Records when present in JVM. by @staale in #2201
- Small adjustments to the new record code. by @eamonnmcmanus in #2219
- Bump jackson-databind from 2.13.4 to 2.13.4.1 by @dependabot in #2222
- Bump jackson-databind from 2.13.4.1 to 2.13.4.2 by @dependabot in #2223
- Add
JsonArray.asList
andJsonObject.asMap
view methods by @Marcono1234 in #2225 - Adjust Record adapter and extend test coverage by @Marcono1234 in #2224
- Small tweaks to fix Error Prone warnings. by @eamonnmcmanus in #2227
- Automatically replace version references on
release:prepare
by @Marcono1234 in #2212 - Revise the version regex in
GsonVersionDiagnosticsTest
. by @eamonnmcmanus in #2228
New Contributors
- @bufistov made their first contribution in #1555
- @JamesZBL made their first contribution in #1246
- @xtay2 made their first contribution in #2169
- @deeptimarrivada1 made their first contribution in #2192
- @kb-1000 made their first contribution in #2196
- @BillyGalbreath made their first contribution in #2213
- @staale made their first contribution in #2201
Full Changelog: gson-parent-2.9.1...gson-parent-2.10
Gson 2.9.1
- Make
Object
andJsonElement
deserialization iterative rather than recursive (#1912) - Added parsing support for enum that has overridden toString() method (#1950)
- Removed support for building Gson with Gradle (#2081)
- Removed obsolete
codegen
hierarchy (#2099) - Add support for reflection access filter (#1905)
- Improve
TypeToken
creation validation (#2072) - Add explicit support for
float
inJsonWriter
(#2130, #2132) - Fail when parsing invalid local date (#2134)
Also many small improvements to javadoc.
Gson 2.9.0
The minimum supported Java version changes from 6 to 7.
- Change target Java version to 7 (#2043)
- Put
module-info.class
into Multi-Release JAR folder (#2013) - Improve error message when abstract class cannot be constructed (#1814)
- Support EnumMap deserialization (#2071)
- Add LazilyParsedNumber default adapter (#2060)
- Fix JsonReader.hasNext() returning true at end of document (#2061)
- Remove Gradle build support. Build script was outdated and not actively maintained anymore (#2063)
- Add
GsonBuilder.disableJdkUnsafe()
(#1904) - Add
UPPER_CASE_WITH_UNDERSCORES
in FieldNamingPolicy (#2024) - Fix failing to serialize Collection or Map with inaccessible constructor (#1902)
- Improve TreeTypeAdapter thread-safety (#1976)
- Fix
Gson.newJsonWriter
ignoring lenient and HTML-safe setting (#1989) - Delete unused LinkedHashTreeMap (#1992)
- Make default adapters stricter; improve exception messages (#2000)
- Fix
FieldNamingPolicy.upperCaseFirstLetter
uppercasing non-letter (#2004)
Thanks to our contributors, especially @Marcono1234!
Gson 2.8.9
- Make OSGi bundle's dependency on
sun.misc
optional (#1993). - Deprecate
Gson.excluder()
exposing internalExcluder
class (#1986). - Prevent Java deserialization of internal classes (#1991).
- Improve number strategy implementation (#1987).
- Fix LongSerializationPolicy null handling being inconsistent with Gson (#1990).
- Support arbitrary Number implementation for Object and Number deserialization (#1290).
- Bump proguard-maven-plugin from 2.4.0 to 2.5.1 (#1980).
- Don't exclude static local classes (#1969).
- Fix
RuntimeTypeAdapterFactory
depending on internalStreams
class (#1959). - Improve Maven build (#1964).
- Make dependency on
java.sql
optional (#1707).