* Add Troubleshooting Guide entry for custom adapter being unused
* Extend documentation
* Fix line endings
* Mention missing adapter in case of "Expected BEGIN_OBJECT ..." exception
* Fix `GsonBuilder.setDateFormat` ignoring partial DEFAULT; deprecate `setDateFormat(int)`
* Remove date format methods not used by main code
* Adjust example
* Adds support to `BigDecimal`
Adds to the JsonPrimitive#equals the possibility to support BigDecimal
* Adds test
Adds test to check if the equals work with BigDecimals. Code snippet from issue #904
* Implements review comments
Replaces the `.equals` method with the `compareTo` in the `JsonPrimitive#equals`
Change the ternary operator from `||` to `&&` so we are sure that both are `BigDecimal`
Implements tests
* Changes to follow the google-style-guide
* implements review comment
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Fixes the `OperatorPrecedence` warn
* Implements code improvements
- Extracts `thisAsDouble` & `otherAsDouble` variables to avoid double functions calls.
- Adds a comment to improve the code readability.
* Implements `BigDecimal` check in the `JsonPrimitive.equals()`
* Formats the code with `spotless:apply`
---------
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Fix $Gson$Types equals method for TypeVariable when its generic declaration is not a Class
* Test $Gson$Types equals method with TypeVariable when its generic declaration is not a Class
* Add @SuppressWarnings in GsonTypesTest.java
* Support serializing anonymous and local class with custom adapter
* Fix formatting and fix switched 'expected' and 'actual' in EnumTest
* Minor code improvements
---------
Co-authored-by: Éamonn McManus <emcmanus@google.com>
* Enable additional Error Prone checks & fix violations
Some of them also enforce additional Google Java Format requirements which
are not handled by google-java-format, such as disallowing wildcard imports.
Not all experimental checks have been listed because some are not applicable,
such as Dependency Injection framework checks, or checks related to Guava's
immutable collections (since Gson's main code does not have a dependency on
Guava).
Other checks have been omitted because they are probably not relevant
(this was a subjective choice), or would require larger refactoring or
would flag issues with the public API, which cannot be changed easily.
* Address review feedback
---------
Co-authored-by: Éamonn McManus <emcmanus@google.com>
* Fix DateFormat time zone is not restored and add Test.
* delete the test and make sure mvn clean test -X can be SUCCESS
* delete the test and make sure mvn clean test -X can be SUCCESS
* add test
* restore the DateFormat time zone in SqlDateTypeAdapter and SqlTimeTypeAdapter
* Adjust the code according to the code review feedback.
* Adjust the code according to the code review feedback.
* Adjust the code according to the code review feedback.
* Adjust the Test
* fix Werror error
* Adjust the DefaultDateTypeAdapterTest according to the code review feedback.
---------
Co-authored-by: Carpe-Wang <wangcarpe@126.com>
* Add CI build using JDK 21
This is mainly to make sure that besides the known JDK 21 build
incompatibilities Gson can be built and run using JDK 21.
* Update ProGuard
* Update Protobuf
3.25.1 is actually newer than 4.0.0-rc-2
* Perform minor code clean-up
Notable changes:
- Replace most usages of `<code>` with `{@code ...}` in Javadoc
- Add proper summary sentence to `GsonBuilder.enableComplexMapKeySerialization`
- Extend documentation for `GsonBuilder.setDateFormat` methods
- Fix `TypeToken.isAssignableFrom(Type)` throwing AssertionError in some cases
Maybe the method should not throw an exception in the first place, but it
might not matter much since it is deprecated already anyway.
- Remove outdated `throws NumberFormatException` from internal
`JsonReader.nextQuotedValue`; the behavior had been changed by
85ebaf7c35
- Fix incorrect documentation on JsonScope fields
- Fix unit tests having 'expected' and 'actual' switched
- Use dedicated Truth methods instead of `isTrue()` / `isFalse()`
- Use common helper methods in JsonWriterTest to avoid duplication
* Implement `toString()` for ReflectionAccessFilter constants
* Address most of the review comments
* Add comment about `source.scm.tag=HEAD` warning
Actually it looks like the warning is not actually caused by usage of
`HEAD` as value, but rather because the project has a snapshot version
during development (which is expected though), see
https://github.com/apache/maven-artifact-plugin/blob/maven-artifact-plugin-3.5.0/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java#L140
But this is not a problem either since during release a non-snapshot
version is used.
`DateFormat` validates these arguments as well, but it is currently not
documented, see https://bugs.openjdk.org/browse/JDK-8319628.
Also moves the other tests for `setDateFormat(String)` from
DefaultTypeAdaptersTest to GsonBuilderTest.
However, it might still be necessary to use the same OS and JDK version
to actually be able to create identical artifacts.
This commit also formats the `pom.xml` files in the way the Maven Release
Plugin would.
* validating the date format, add test case, since NumberFormatException extends IllegalArgumentException, it is only necessary to write IllegalArgumentException.
* Apply code formatting with Spotless
---------
Co-authored-by: Carpe-Wang <wangcarpe@126.com>
* Formatting follow-up
- Adds formatting commits to .git-blame-ignore-revs so that they don't
distract during Git blame
- Restores hard line breaks in Troubleshooting.md using `\` instead of
trailing spaces
- Changes formatting of some string literals and comments
- Fixes accidental Javadoc and comment issues introduced by manual changes
of formatting commit
- Fixes license header in $Gson$Types.java erroneously being a Javadoc
comment and being reformatted
- Slightly changes `JsonReader` `getPath` and `getPreviousPath` documentation
to help Javadoc detect first sentence as summary
* Remove `spotless:off` markers
* Add empty line before comment
* Check format for .github YAML files
* Code changes and tests for #2436 to throw exception when trying to register adapter for Object or JsonElement
* #2436 - Updates to User guide & comments to indicate exception cases and fix for 7 test cases of Parameterized Type
* #2436 - Fixes as per the review comments.
* #2436 - Refactored as per latest review comments + throwing error message.
* #2436 - added a clarifying comment in a positive test case.
* #2436 - formatting and minor changes as per review.
* Update gson/src/main/java/com/google/gson/GsonBuilder.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/GsonBuilderTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/GsonBuilderTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
---------
Co-authored-by: Sachin Patil <sachin.patil2@capitalone.com>
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Only create one BoundField instance per field in ReflectiveTypeAdapterFactory
Instead of creating a BoundField for every possible name of a field (for
SerializedName usage) and then storing for that BoundField whether it is
serialized or deserialized, instead only create one BoundField and then have
a separate Map<String, BoundField> for deserialized fields, and a separate
List<BoundField> for serialized fields.
* Fix indentation
Recent versions of javac emit a warning if a serializable class has
a non-transient instance field with a declared type that does not
inherit `Serializable`. In this context, we know that the actual
values will always be serializable.
Previous fix in 392cc65ff3 only covered writing
name as top level value, but not when trying to write name inside JSON array.
Removed `stackSize == 0` check from `JsonWriter.name` because that is done
already by `peek()` call.
* Document how `JsonAdapter` creates adapter instances & add tests
* Extend `JsonAdapter.nullSafe()` documentation
* Improve test for JsonAdapter factory returning null
Existing test `JsonAdapterNullSafeTest` had misleading comments; while it
did in the end detect if null had not been handled correctly, that only
worked because the field `JsonAdapterFactory.recursiveCall` is static and
one test method therefore affected the state of the other test method.
If the test methods were run separately in different test runs, they would
not have detected if null was handled correctly, because the factory would
not have returned null.
* Extend JsonAdapter nullSafe test
* Extend test
* Fix `Gson.getDelegateAdapter` not working properly for `JsonAdapter`
* Address review feedback and add comments regarding thread-safety
* Revert InstanceCreator instance validation
* Disallow `null` as `skipPast`
* Avoid `equals` usage in `getDelegateAdapter` & minor other changes
Previously `getDelegateAdapter` called `factories.contains(skipPast)`,
but unlike the other comparisons which check for reference equality,
that would have used the `equals` method.
This could lead to spurious "GSON cannot serialize ..." exceptions
if two factory instances compared equal, but the one provided as
`skipPast` had not been registered yet.
* Prevent `TypeToken` from capturing type variables
* Use hyphen for term "type-safe"
Not completely sure if that is grammatically correct, but it might make the
text a bit easier to understand.
* Update Troubleshooting Guide URLs in tests from 'master' to 'main'
* Rename system property
* Simplify system property check
* Add integration test for GraalVM Native Image
* Enable 'quickBuild' mode
Seems to improve build speed, and at least for the previous issue with
`RecordComponent` still causes test failures (as expected) if the fix
is reverted.