gson-comments/gson/src/main/java/com/google/gson/internal
Ståle Undheim a0dc7bfddd
Support Java Records when present in JVM. (#2201)
* Support Java Records when present in JVM.

Fixes google/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
2022-10-11 09:13:49 -07:00
..
bind Support Java Records when present in JVM. (#2201) 2022-10-11 09:13:49 -07:00
reflect Support Java Records when present in JVM. (#2201) 2022-10-11 09:13:49 -07:00
sql Make default adapters stricter; improve exception messages (#2000) 2021-11-01 15:08:04 -07:00
$Gson$Preconditions.java Replace $Gson$Preconditions.checkNotNull with Objects.requireNonNull (#2180) 2022-08-22 07:22:32 -07:00
$Gson$Types.java Replace $Gson$Preconditions.checkNotNull with Objects.requireNonNull (#2180) 2022-08-22 07:22:32 -07:00
ConstructorConstructor.java Only create one UnsafeAllocator instance (#2196) 2022-09-29 15:59:47 -07:00
Excluder.java Improve versioning support documentation and validate version (#2214) 2022-10-02 16:38:43 -07:00
JavaVersion.java Private constructor (#1324) 2018-05-21 20:04:22 -07:00
JsonReaderInternalAccess.java Don't allocate a whole bunch of objects each time we deserialize a map key. This saves 20% on bug 375's benchmark. 2011-11-26 15:36:08 +00:00
LazilyParsedNumber.java Fail Maven build on compiler warnings; remove some warning suppressions (#2183) 2022-08-26 17:36:18 -07:00
LinkedTreeMap.java Fail Maven build on compiler warnings; remove some warning suppressions (#2183) 2022-08-26 17:36:18 -07:00
ObjectConstructor.java Down to 22 failing tests. 2011-09-11 07:04:56 +00:00
package-info.java Added a warning in the documentation of the internal package. 2011-04-06 01:08:12 +00:00
PreJava9DateFormatProvider.java fix Java9 DateFormat changes (#1211) 2017-12-30 00:44:43 +05:30
Primitives.java Refactor primitives class 2019-04-15 11:08:31 -04:00
ReflectionAccessFilterHelper.java Add support for reflection access filter (#1905) 2022-04-17 09:05:18 -07:00
Streams.java Replace $Gson$Preconditions.checkNotNull with Objects.requireNonNull (#2180) 2022-08-22 07:22:32 -07:00
UnsafeAllocator.java Only create one UnsafeAllocator instance (#2196) 2022-09-29 15:59:47 -07:00