* 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
Disables the download transfer progress which is shown when Maven downloads
(or uploads) artifacts which are not available in the local repository.
This download progress can be quite verbose and is normally not that relevant.
* Add a currently-failing test for Java records and `@Ignore` it.
Also do the Maven gymastics required to ensure that this test only runs on Java
versions ≥17. (It would also work on Java 16, but 17 is all we have in the CI.)
Fix some compilation problems I saw when running locally, which for some reason
don't show up in the CI.
* Suppress some new lint options that trigger `-Werror`.
We may fix these later. (Every test will need an explicit constructor!)
* Select Java version with maven.compiler.release and maven.compiler.testRelease.
Use `assumeNotNull` rather than an if-statement.
* Specify <release>11</release> for javadoc.
* Restore the @see for AccessibleObject.
* Build on JDK 8 and 17 as well as 11.
* Remove JDK 8 for now.
`DefaultDateTypeAdapterTest` fails.
* Tweak javadoc to avoid warnings.
Mostly these are about using `<h3>` when the previous tag was `<h1>`,
and the like. This previous tag might be implicit (part of what javadoc
itself outputs rather than the HTML in doc comments).
Apparently JDK 11 puts method javadoc inside `<h2>` while JDK 11 puts it
inside `<h3>`. Or something like that. Anyway it doesn't appear to be
possible to use `<h3>` _or_ `<h4>` and please both.
* Add Gson.fromJson(..., TypeToken) overloads
Previously only Gson.fromJson(..., Type) existed which is however not
type-safe since the generic type parameter T used for the return type is
not bound.
Since these methods are often used in the form
gson.fromJson(..., new TypeToken<...>(){}.getType())
this commit now adds overloads which accept a TypeToken and are therefore
more type-safe.
Additional changes:
- Fixed some grammar mistakes
- Added javadoc @see tags
- Consistently write "JSON" in uppercase
- More precise placement of @SuppressWarnings("unchecked")
* Add to Gson.fromJson javadoc that JSON is fully consumed
The newly added documentation deliberately does not state which exception
is thrown because Gson.assertFullConsumption could throw either a
JsonIOException or a JsonSyntaxException.
* Remove unnecessary wrapping and unwrapping as TypeToken in Gson.fromJson
Since the actual implementation of Gson.fromJson is TypeToken based, the
TypeToken variant overloads are now the "main" implementation and the other
overloads delegate to them.
Previously the Type variant overloads were the "main" implementation which
caused `TypeToken.getType()` followed by `TypeToken.get(...)` when the
TypeToken variant overloads were used.
* Trim source code whitespaces
* Fix Gson.fromJson(JsonReader, Class) not casting read Object
To be consistent with the other Gson.fromJson(..., Class) overloads the
method should cast the result.
* Replace User Guide link in Gson documentation
* Remove more references to fromJson(..., Type)
* Extend documentation for fromJson(JsonReader, ...)
* Replace some TypeToken.getType() usages
* Address feedback; improve documentation
* Remove fromJson(JsonReader, Class) again
As noticed during review adding this method is source incompatible.