Commit Graph

58 Commits

Author SHA1 Message Date
Maicol
0a42c31efe
Code cleanup (#2282)
* Simplify `if` condition in JsonReader.peekNumber()

* Remove `if` to simplify a `return` in Excluder.excludeClassChecks()

* Remove redundant variable in Gson.fromJson()

* equal condition replace by `Objects.equals()` in $Gson$Types.equal()

* equal condition replace by `Objects.equals()` in LinkedTreeMap.equal()

* Replace `switch` with `if` in UtcDateTypeAdapter.read()

* Remove redundant `throws` clause in GraphAdapterBuilder.read()

* Remove redundant `throws` clause in JsonTreeReader.UNREADABLE_READER

* Remove redundant `throws` clause in JsonTreeWriter.UNREADABLE_READER

* Remove unnecessary `.initCause()` call

* Remove redundant cast in TreeTypeAdapter.GsonContextImpl.deserialize

* Replace `StringBuilder` with `String`

* Fix the import and restore the `switch`

* Fix the import

* Add the `util.Objects` import

* Fix indentation

* Add a comment to clarify the condition

* Fix indentation

* Fix imports

* Fix indentation

* Fix indentation

* Fix indentation
2022-12-13 08:50:25 -08:00
Marcono1234
2591ede59b
Fix incorrect HTML headings in Javadoc (#2200) 2022-09-24 17:02:11 -07:00
Éamonn McManus
0864a02e86
Build on JDK 17 as well as 11. (#2198)
* 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.
2022-09-23 14:33:28 -07:00
Marcono1234
f7a164d98b
Fail Maven build on compiler warnings; remove some warning suppressions (#2183)
* Fail Maven build on compiler warnings; remove some warning suppressions

* Fix compiler warnings causing failure for newer JDK

* Improve placement of "raw" and "unchecked" warning suppressions

* Adjust javac documentation link

* Fix compilation error on newer JDKs
2022-08-26 17:36:18 -07:00
Éamonn McManus
2deb2099d3
Make RuntimeTypeAdapterFactory recognize subclasses only conditionally. (#2160)
PR #2139 changed this factory so that if given a certain baseType, it will also
recognize any subtype of that type. That is often the right thing to do, but it
is a change in behaviour, and does in fact break at least one current client of
this code. So instead we introduce a new `recognizeSubclasses()` method that
triggers this behaviour. When the method is not called, we revert to the old
behaviour of only recognizing instances of the exact class `baseType`.
2022-07-27 12:18:20 -07:00
Thomas Oster
2eb37589b5
Fix RuntimeTypeAdapterFactory (#2139)
* Change the RuntimeTypeAdapterFactoryTest, so it fails because of #712

* Fix RuntimeTypeAdapterFactory

Trying to use this class as is results in the type-property not being serialized into the JSON, thus it is not present on deserialization.
The fix from https://github.com/google/gson/issues/712#issuecomment-148955110 works. No idea why this is not merged yet.
2022-07-21 10:28:48 -07:00
Marcono1234
4dda4ec5ba
Use diamond operator when creating generic instances (#2104) 2022-04-17 15:27:21 -07:00
Marcono1234
e82637c485
Add support for reflection access filter (#1905)
* Add support for reflection access filter

* Improve documentation

* Fix compilation errors

* Relax handling for BLOCK_ALL when invoking default constructor

* Improve handling for inherited fields

* Fix accessible test failing for static fields

* Simplify ReflectiveTypeAdapterFactory field writing

* Fix GsonBuilder changes affecting created Gson instances

* Improve documentation

* Improve handling for IllegalAccessException

For Java < 9, AccessibleObject.canAccess is not available and therefore checks
might pass even if object is not accessible, causing IllegalAccessException
later.

* Fix incorrect GsonBuilder.addReflectionAccessFilter documentation
2022-04-17 09:05:18 -07:00
Marcono1234
49ddab9eeb
Add CodeQL GitHub code scanning workflow (#2076)
* Add CodeQL GitHub code scanning workflow

* Only compile main sources for code scanning

* Move test .proto  files to test sources

`annotations.proto` also seems to be only relevant for tests because the test
explicitly registers them as extensions. By default the Proto adapter does not
consider them.

* Address some code scanning findings

* Fix some more findings
2022-02-17 18:40:40 -08:00
Marcono1234
615c8835d3
Add GsonBuilder.disableJdkUnsafe() (#1904)
* Add GsonBuilder.disableJdkUnsafe()

* Address review feedback
2021-12-30 15:08:18 -08:00
Marcono1234
6ffcdf3029
Fix Javadoc warnings and errors (#2040) 2021-12-26 15:30:21 -08:00
Marcono1234
26a1928277
Fix RuntimeTypeAdapterFactory depending on internal Streams class (#1959)
* Fix RuntimeTypeAdapterFactory depending on internal Streams class

* Clean up gson-extras project, make it Maven module of gson-parent

* Remove broken test from GraphAdapterBuilderTest
2021-09-17 17:21:37 -07:00
Z
ebe4b581dd
update RawCollectionsExample.java (#1953)
use static method instead deprecated method
2021-09-07 08:02:04 -07:00
Lyubomyr Shaydariv
47b28d99a1 The JavaDoc is now more accurate about the type adapter serialization and deserialization (#1441) 2019-10-28 16:11:15 -07:00
hmble
b046ea28ee
Typo in JavaDoc example 2018-10-10 20:28:10 +05:30
Eric Cochran
d8d8ccb98a Simplify maintainType logic
When we maintain the label value, we do not need to make a new JsonObject and copy over the keys and values when writing. The ordering will change, though. Before this change, it always put the label first.
2018-07-30 13:43:52 -04:00
lucalas
c1e7e2d280 Add possibility to maintain type variable in created pojo (#1342)
Instead of completely remove type variable, give the possibility to decide if maintain type value (if pojo has type variable declaration) or not.
2018-07-20 14:34:45 -07:00
Stefan M
1c09b3f928 Fix well formed exception (#1105)
The previous exception was styled in the following way:
... ["DATE']...
This commit will fix the different quote marks and replace the " with '
2017-06-23 09:32:04 -07:00
Niv Singer
74e37110e5 Avoid NPE in PostConstructAdapterFactory (#1103)
* Avoid NPE in PostConstructAdapterFactory

The RawType's Superclass might be null. This happens, for example, when the type is a collection.

* Add test case for NPE in PostConstructAdapterFactory

* Improve the code quality of PostConstructAdapterFactoryTest

* Improve the code quality of PostConstructAdapterFactoryTest

* Improve the code quality of PostConstructAdapterFactoryTest
2017-06-19 18:04:19 -07:00
Inderjeet Singh
4512f31c69 Added PostConstruct Factory sample in Extras. 2016-09-16 17:35:34 -07:00
Juan Andrés Diana
86d88c32cf The method registerTypeAdapterFactory accepts a TypeAdapterFactory instance only. 2016-05-25 15:49:39 -03:00
Juan Andrés Diana
d4a9eb4e7b Docs fix for the RuntimeTypeAdapterFactory class.
Instances of classes that implement RuntimeTypeAdapterFactory should be registered using the registerTypeAdapterFactory method instead of registerTypeAdapter.
2016-05-24 16:45:55 -03:00
Egor N
edaf59e178 Fix RuntimeTypeAdapterFactory javadoc 2016-02-19 16:14:55 +02:00
Lachlan Coote
1867457030 fix #680 - make RuntimeTypeAdapterFactory null-safe 2015-08-05 16:27:18 -07:00
Inderjeet Singh
0c3b9670f0 Ensuring that UTC date adapter serializes nulls correctly 2014-12-05 22:12:54 +00:00
Inderjeet Singh
f0f9ce42f4 using only Jackson iso8601 implementation for UTC date adapter 2014-12-05 08:28:25 +00:00
Inderjeet Singh
0e3708be82 updated UTC type adapter to support JDK 1.6 using Jackson ISO8601 parsing util 2014-12-05 07:41:08 +00:00
Inderjeet Singh
255f2e2847 added a sample Date type adapter for UTC 2014-12-05 00:16:24 +00:00
Inderjeet Singh
1d9e86e27c fixed extras build 2014-12-04 22:07:13 +00:00
Jesse Wilson
af4879dbb7 Move interceptors from 'alpha' to 'extras'.
This makes the feature less risky to use! It now uses our
TypeAdapterFactory infrastructure rather than relying on
parallel infrastructure.
2012-10-23 17:36:30 +00:00
Inderjeet Singh
42e35e9f90 updated oss-parent version to 7 in gson-extras pom.
fixed some eclipse warnings.
2012-08-01 20:57:51 +00:00
Inderjeet Singh
7a5cef9305 Revised to the new name getDelegateAdapter. 2012-04-14 19:04:14 +00:00
Jesse Wilson
efde6674e1 Test that GraphAdapterBuilder works with collections. 2012-01-01 15:48:01 +00:00
Jesse Wilson
6cca23c172 Get GraphAdapterBuilder working for serialization and deserialization using InstanceCreators to get a sneak peek at a value under construction. 2012-01-01 13:42:44 +00:00
Jesse Wilson
796a381279 Kill GsonInternalAccess. Clients to this were all broken because nobody was ever assigning INSTANCE. 2012-01-01 12:42:20 +00:00
Jesse Wilson
ecdf9150f6 Hide Gson.getNextAdapter() for the current release. 2011-12-31 05:30:40 +00:00
Jesse Wilson
4057b98bab Implement all but the most difficult part of graph type adapter's deserialization. The catch is we want to return an instance that we don't have yet. It's on the stack, but we don't have a handle to it because it's inside the 'nextTypeAdapter' who is busy populating its fields. 2011-12-30 08:27:24 +00:00
Jesse Wilson
6ec6caa49d New extension: handle circular references.
Serialize graphs of objects by assigning each instance a generated ID and writing the complete graph out as a list. The output for a cycle of Rock/Scissors/Paper looks like this:

{
  '0x1':{'name':'ROCK','beats':'0x2'},
  '0x2':{'name':'SCISSORS','beats':'0x3'},
  '0x3':{'name':'PAPER','beats':'0x1'}
}

This is work towards issue 137. The hard part is going to be deserializing that back into a graph.
2011-12-30 07:34:43 +00:00
Jesse Wilson
d7fbac0384 Rename TypeAdapter.Factory to TypeAdapterFactory. 2011-12-23 18:27:13 +00:00
Jesse Wilson
dce4e463d9 Apply variable name improvement from issue 385.
Fixes issue 385.
2011-12-16 04:55:54 +00:00
Jesse Wilson
f602bce9f5 Nice documentation for TypeAdapter. 2011-12-03 19:46:25 +00:00
Jesse Wilson
26ab404599 Cleanup names for TypeAdapters. 2011-12-02 22:57:30 +00:00
Jesse Wilson
f39ac8d946 Update extras to build after today's Gson/MiniGson refactoring. 2011-11-21 05:09:14 +00:00
Jesse Wilson
b892c85909 Sync RuntimeTypeAdapterFactory to recent internal API changes 2011-10-19 17:49:02 +00:00
Jesse Wilson
46e65a77c5 Convert RuntimeTypeAdapter to a TypeAdapterFactory; this avoids the need for serializeDefault() 2011-09-28 19:14:46 +00:00
Jesse Wilson
60e6ed912d Promote MiniGson to gson.internal.bind 2011-08-03 00:25:10 +00:00
Jesse Wilson
759eb8ede5 Factory always wanted to be public. 2011-08-03 00:17:17 +00:00
Jesse Wilson
4b042671af Cleanup after experimenting with specializing BoundField by type (ie. Field.setInt() to avoid autoboxing) 2011-07-15 14:37:05 +00:00
Jesse Wilson
3c4d121dc8 Fix integration tests that fell out from some benchmarking. 2011-07-15 13:43:52 +00:00
Jesse Wilson
041d499a7c Fix serialization where one type depends (possibly indireclty) on itself! 2011-07-12 19:39:27 +00:00