* Rewrite the `testParsingDatesFormattedWithSystemLocale()`, Fix#2199
* Format the test
* Format the code following Google Java Style Guide
* Revert "Format the code following Google Java Style Guide"
This reverts commit f5e2e16b290a4bed09ed7fcc162d4a2529fe4c38.
* Remove EOFException special casing of JsonStreamParser.next()
The previous behavior violated the Iterator contract where for
`JsonStreamParser("[")` a call to `hasNext()` would return true,
but `next()` would throw a NoSuchElementException.
* Fix incorrect documented thrown exception type for JsonStreamParser
* Fix non-threadsafe creation of adapter for type with cyclic dependency
* Improve handling of broken adapters during Gson.getAdapter(...) call
* Improve test
* Slightly improve implementation and extend tests
* Simplify getAdapter implementation
* Convert GsonTest to JUnit 4 test
* Clarify getAdapter concurrency behavior
* Adjust version numbers and a test to conform to the SemVer spec.
Gson releases since 2.8.0 have been following this spec. We mistakenly released 2.10
without the .0 patch version, and adjusted `GsonVersionDiagnosticsTest` so it would
accept that, as well as the two-digit `10`. Here we make the test no longer accept
versions without a patch number, while still accepting two-digit minor versions of course.
We also change the snapshot version to 2.11.0-SNAPSHOT instead of 2.11-SNAPSHOT.
* Add 2.10 changes to CHANGELOG; minor release follow-ups
* Use GitHub URLs in CHANGELOG
GitHub automatically displays them only as short reference with link and
additionally shows a preview when hovering over them.
* Add `id` to pom.xml developer entry
Otherwise BND plugin shows a warning.
* Run unit tests during release preparation
* Move git option before pathspec
* Automatically replace version references on `release:prepare`
* Specify encoding and improve placeholder replacements
* Add `since $next-version$` for `JsonArray.asList` and `JsonObject.asMap`
* Adjust Record adapter and extend test coverage
* Address review feedback
* Make constructor string more concise
* Add tests for Gson default behavior for static fields
* Improve exception for deserializing static final field
Previously it would report "Unexpected IllegalAccessException occurred..."
due to the uncaught IllegalAccessException.
* Improve handling of exception thrown by accessor
Such an exception is not 'unexpected' (which was claimed by the previous
exception handling) because user code could throw it.
* Improve constructor invocation exception handling and add tests
* Small adjustments to the new record code.
* Replace wildcard imports with single imports.
* Enable `Java17RecordTest` and fix its many previously-hidden problems.
* Use a `Map` to get primitive zero values rather than a potentially-expensive reflective trick.
* Apply some automated code fixes.
* Address review comments.
* Support Java Records when present in JVM.
Fixesgoogle/gson#1794
Added support in the ReflectionHelper to detect if a class is a record
on the JVM (via reflection), and if so, we will create a special
RecordAdapter to deserialize records, using the canoncial constructor.
The ReflectionTypeAdapterFactory had to be refactored a bit to support
this. The Adapter class inside the factory is now abstract, with
concrete implementations for normal field reflection and for Records.
The common code is in the Adapter, with each implementation
deserializing values into an intermediary object.
For the FieldReflectionAdapter, the intermediary is actually the final
result, and field access is used to write to fields as before. For the
RecordAdapter the intermediary is the Object[] to pass to the Record
constructor.
* Fixed comments from @Marcono1234
Also updated so that we now use the record accessor method to read out
values from a record, so that direct field access is not necessary.
Also added some tests, that should only execute on Java versions with
record support, and be ignored for other JVMs
* Fixed additional comments from @Marcono1234
* Made Adapter in ReflectiveTypeAdapterFactory public
Fix comment from @eamonnmcmanus
* Fix TypeAdapterRuntimeTypeWrapper not detecting reflective TreeTypeAdapter
Previously on serialization TypeAdapterRuntimeTypeWrapper preferred a
TreeTypeAdapter without `serializer` which falls back to the reflective
adapter. This behavior was incorrect because it caused the reflective
adapter for a Base class to be used for serialization (indirectly as
TreeTypeAdapter delegate) instead of using the reflective adapter for
a Subclass extending Base.
* Address review feedback
* Convert TypeAdapterRuntimeTypeWrapperTest to JUnit 4 test
* Prefer wrapped reflective adapter for serialization of subclass
* Detect reflective adapter used as delegate for Gson.FutureTypeAdapter
* Tiny style tweak.
Co-authored-by: Éamonn McManus <emcmanus@google.com>
* Fix JsonReader.skipValue() not behaving properly at end of document
JsonReader implementation erroneously reset `peeked` to PEEKED_NONE;
JsonTreeReader threw ArrayIndexOutOfBoundsException.
* Fix JsonReader.skipValue() not behaving properly at end of array and object
For JsonReader this caused an IllegalStateException (in the past it caused
JsonReader to get stuck in an infinite loop); for JsonTreeReader it only
popped the empty iterator but not the JsonArray or JsonObject, which caused
peek() to again report END_ARRAY or END_OBJECT.
* Only have JsonReader.skipValue() overwrite path name when name was skipped
This improves the JSON path when the value for a property was skipped and
before the subsequent property (or the end of the object) getPath() is called.
* Address feedback; improve test coverage
Co-authored-by: Éamonn McManus <emcmanus@google.com>
* Perform numeric conversion for primitive numeric type adapters
This should probably not be visible to the user unless they use the
non-typesafe `Gson.toJson(Object, Type)` where unrelated number types can
be used, or when malformed generic containers are used. For example a
`List<Byte>` containing a Float.
This change also has the advantage of avoiding `JsonWriter.value(Number)`
for primitive type adapters. That method has some overhead because it needs
to make sure that the value is a valid JSON number. However, for primitive
numbers this check is redundant.
* Don't call `JsonWriter.value(float)` for backward compatibility
* Fix typo in comments