gson-comments/gson
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
..
src Support Java Records when present in JVM. (#2201) 2022-10-11 09:13:49 -07:00
bnd.bnd Change target Java version to 7 (#2043) 2021-12-31 07:20:29 -08:00
LICENSE Updating License to contain the full text. 2011-04-12 21:21:39 +00:00
pom.xml Follow-up for record test build changes (#2207) 2022-09-27 23:02:15 -07:00
README.md Add READMEs to Maven modules (#2039) 2021-12-27 10:17:41 -08:00

gson

This Maven module contains the Gson source code. The artifacts created by this module are deployed to Maven Central under the coordinates com.google.code.gson:gson.