* 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
* Strict mode for JSON parsing (#2323)
* Feat #6: Add strict flag to Gson and GsonBuilder
* Test #2: Add failing tests for capitalized keywords
* Feat #2: JsonReader does not read (partially) capitalized keywords if strict mode is used
* Feat #3: Added implementation and tests for JSONReader not accepting specific escape sequence representing in strict mode
* Test #3: Simplify test cases by removing unnecessary array
* Feat #3: Improve error by including the illegal character
* Feat #5: JsonReader does not allow unespaced control flow characters in strict mode
* Test #5: Test unespaced control flow characters in strict mode
* Feat #4: Disallow espaced newline character in strict mode
* Test #4: Add tests for (dis)allowing newline character depensding on strictness
* Test #5: Test case for unescaped control char in non-strict mode
* Test #2: Simplify test cases
* Feat #13: Change leniency API to Strictness enum in JsonReader, Gson, and GsonBuilder
* Feat #15: Change JsonWriter API to also use Strictness
* Test #15: Test Strictness in JsonWriter API
* Doc #15: Add and update documentation for Strictness in JsonWriter API
* refactor #12: Fixed typos and empty catch brackets in tests
* refactor #12: Resolved importing wildcards, made some lines adhere to Google java style
* #5 Add test case for unescaped control characters
* Feat #5: add new lines to make JsonReader able to detect unescaped control characters (U+0000 through U+001F) and throw exceptions.
* Feat #5: add new lines to make JsonReader able to detect unescaped control characters (U+0000 through U+001F) and throw exceptions.
* Test #11: Added two tests for testing implementation of control character handling in strict mode and moved the implementation to nextQuotedValue
* Test #11: Added two tests for testing implementation of control character handling in strict mode and moved the implementation to nextQuotedValue
---------
Co-authored-by: LMC117 <2295699210@qq.com>
Co-authored-by: Marten Voorberg <martenvoorberg@gmail.com>
* Doc #17: Add and change javadoc of public methods
* Doc #17: Update JavaDoc in JsonReader and Strictness
* Doc #17: Update JavaDoc in Gson and GsonBuilder
* Test #34: Add tests for setting strictness through GsonBuilder
* Fix: Add Fix broken test
* Fix: Invalid JavaDoc in Gson.java
* Doc #17: update outdated javadoc
* #37: Resolve more PR feedback
* Fix#37: Resolve various PR comments
* Fix#37: Resolve various PR comments
* Refactor #35: Refactor JsonReader#peekKeyword to reduce the amount of strictness checks (#39)
* Doc #40: Update JavaDoc based on PR feedback
* Doc #40: Update old RFC in GsonBuilder documentation
* Doc #40: Fix formatting error in JavaDoc
* Doc #40: Add tests for setting strictness and lenient to JsonReaderTest
* Test #43: Changed tests to make use of assertThrows
* test #43: Changed tests to make use of assertThrows as per feedback
* Test #43: Update JsonWriterTest#testStrictnessNull to use assertThrows
* Test #43: Update JsonWriterTest#testStrictnessNull to use assertThrows
* test #43: Resolve PR recommendations
* Test #43: Mini change to TC
* Test #43: Mini change to TC
---------
Co-authored-by: Marten Voorberg <martenvoorberg@gmail.com>
* doc #46: Resolved comments in main PR
* Feat #45: Change Gson.fromJson and Gson.toJson to be strict when the provided writer/reader is strict
* Fix#45: Small type
* Update gson/src/test/java/com/google/gson/stream/JsonReaderTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Fix#45: Resolve various comments by Marcono1234
* Update gson/src/main/java/com/google/gson/GsonBuilder.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Fix#45: Resolve various comments by Marcono1234
* Fix#45: Resolve various comments by eamonmcmanus
* Strictness mode follow-up
* Update Troubleshooting.md and Gson default lenient mode documentation
* Always use GSON strictness when set.
* Rename Strictness.DEFAULT to Strictness.LEGACY_STRICT
* Update JavaDoc with new strictness functionality
* Replace default with legacy strict for JsonReader javadoc
* Add JSONReader test cases for U2028 and U2029
* Refactor JSONReader#peekKeyWord() based on @eamonmcmanus's suggestion
* Deprecate setLenient in favor of setStrictness
---------
Co-authored-by: Carl Peterson <unknown>
Co-authored-by: Gustaf Johansson <gustajoh@kth.se>
Co-authored-by: gustajoh <58432871+gustajoh@users.noreply.github.com>
Co-authored-by: LMC117 <2295699210@qq.com>
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Strictness follow-up (#2408)
* Strictness mode follow-up
- Remove mentions of `null` Gson strictness; this is an implementation detail
- Fix incorrect / outdated documentation
- Reduce links to RFC; if there is already a link to it in a previous sentence
don't link to it again
- Extend and update tests
- Minor punctuation changes in documentation for consistency
* Deprecate `setLenient` methods
* `strictness2` fixes & improvements (#2456)
* Adjust ProGuard default rules and shrinking tests (#2420)
* Adjust ProGuard default rules and shrinking tests
* Adjust comment
* Add shrinking test for class without no-args constructor; improve docs
* Improve Unsafe mention in Troubleshooting Guide
* Improve comment for `-if class *`
* Bump com.google.guava:guava from 32.0.1-jre to 32.1.1-jre (#2444)
Bumps [com.google.guava:guava](https://github.com/google/guava) from 32.0.1-jre to 32.1.1-jre.
- [Release notes](https://github.com/google/guava/releases)
- [Commits](https://github.com/google/guava/commits)
---
updated-dependencies:
- dependency-name: com.google.guava:guava
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Bump com.google.guava:guava-testlib from 32.0.1-jre to 32.1.1-jre (#2443)
Bumps [com.google.guava:guava-testlib](https://github.com/google/guava) from 32.0.1-jre to 32.1.1-jre.
- [Release notes](https://github.com/google/guava/releases)
- [Commits](https://github.com/google/guava/commits)
---
updated-dependencies:
- dependency-name: com.google.guava:guava-testlib
dependency-type: direct:development
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Support non-generic type for `TypeToken.getParameterized` for legacy reasons (#2447)
This partially restores the behavior before a589ef2008,
except that back then for a non-generic type a bogus `TypeToken(ParameterizedType)`
was created, whereas now a `TypeToken(Class)` is created instead.
* Fixed Typo in GsonBuilder.java (#2449)
* Make date-formatting tests less fragile with regular expressions. (#2450)
* Make date-formatting tests less fragile with regular expressions.
This is not great. We should really ensure that formatted dates are the same
regardless of JDK version. There is code that attempts to do that but it is not
really effective. So for now we fudge around the differences by using regular
expressions to paper over the differences.
* Temporarily add test-debugging code.
* Another attempt at debugging a test failure.
* Fix pattern in assertion.
* Modification in test cases (#2454)
* Fixed Typo in GsonBuilder.java
* Suggestions on Test cases
* Modified test cases using assertThrows method (JUnit)
* Update gson/src/test/java/com/google/gson/JsonArrayAsListTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/GsonTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/JsonArrayAsListTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/JsonStreamParserTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/JsonStreamParserTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/JsonStreamParserTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/ToNumberPolicyTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/TypeAdapterTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/TypeAdapterTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/ToNumberPolicyTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Update gson/src/test/java/com/google/gson/ToNumberPolicyTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
---------
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Minor follow-up changes
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: elevne <97422844+elevne@users.noreply.github.com>
Co-authored-by: Éamonn McManus <emcmanus@google.com>
Co-authored-by: Wonil <cwi5525@naver.com>
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Marten <martenvoorberg@gmail.com>
Co-authored-by: Gustaf Johansson <gustajoh@kth.se>
Co-authored-by: gustajoh <58432871+gustajoh@users.noreply.github.com>
Co-authored-by: LMC117 <2295699210@qq.com>
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: elevne <97422844+elevne@users.noreply.github.com>
Co-authored-by: Wonil <cwi5525@naver.com>
This partially restores the behavior before a589ef2008,
except that back then for a non-generic type a bogus `TypeToken(ParameterizedType)`
was created, whereas now a `TypeToken(Class)` is created instead.
* Adjust ProGuard default rules and shrinking tests
* Adjust comment
* Add shrinking test for class without no-args constructor; improve docs
* Improve Unsafe mention in Troubleshooting Guide
* Improve comment for `-if class *`
* Add code shrinking tools integration test
* Keep no-args constructor of classes usable with JsonAdapter
* Add library ProGuard rules for Gson
They are automatically applied for all users of Gson, see
https://developer.android.com/build/shrink-code#configuration-files
* Skip japicmp-maven-plugin for shrinker-test
* Add more tests for JsonAdapter, add tests for generic classes
* Extend default constructor test
* Add Troubleshooting Guide entry for TypeToken
This annotation indicates that return value of the annotated method does
not need to be used. If it is _not_ present on a non-void method, and if
Error Prone's `CheckReturnValue` is active, then calling the method
without using the result is an error. However, we are not enabling
`CheckReturnValue` by default here.
Also update some code that does ignore return values, so that the
returned value is used, if only by assigning it to an unused variable.
* FormattingStyle follow-up
* Add links to FormattingStyle
* Use Truth for FormattingStyleTest
* Reduce pull request scope to Javadoc and minor code changes
* Fix#2334
This commit replaces the `NumberFormatException` with `MalformedJsonException` in the `JsonReader#readEscapeCharacter()` and also fixes the tests.
* Removes white-space
* Adds `@SuppressWarnings("NarrowingCompoundAssignment")`
* Adds `@SuppressWarnings("TypeParameterUnusedInFormals")`
* Adds `@SuppressWarnings("JavaUtilDate")`
* Adds a limit to `String.split()`
* Add `error_prone_annotations` to the `pom.xml`
* Adds `@InlineMe(...)` to deprecated methods
* Adds `@SuppressWarnings("ImmutableEnumChecker")`
* Adds `@SuppressWarnings("ModifiedButNotUsed")`
* Adds `@SuppressWarnings("MixedMutabilityReturnType")`
* Removes an unused import
* Adds `requires` to `module-info.java`
* Adds ErrorProne `link` into `pom.xml`
* Remove unused imports
Removed from:
- ParseBenchmark
* Adds `@SuppressWarnings("EqualsGetClass")`
* Excludes from `proto` just the generated code.
Replaces `.*proto.*` with `.*/generated-test-sources/protobuf/.*` in such way will be excluded just the generated code and not the whole `proto` directory
* Removes an unused variable
Removes the `descriptor` variable because is unused.
* Fixes the `BadImport` warn into `ProtosWithAnnotationsTest`
* Fixes the `BadImport` warns into `ProtosWithAnnotationsTest`
* Enables ErrorProne in `gson/src/test.*`
Removes the `gson/src/test.*` path from the `-XepExcludedPaths` parameter of the ErrorProne plugin
* Fixes `UnusedVariable` warns
This commit fix all `UnusedVariable` warns given by ErrorProne in the `gson/src/test.*` path.
Some field is annotated with `@Keep` that means is used by reflection.
In some other case the record is annotated with `@SuppressWarnings("unused")`
* Fixes `JavaUtilDate` warns
This commit fix all `JavaUtilDate` warns given by ErrorProne in the `gson/src/test.*` path.
Classes/Methods are annotated with `@SuppressWarnings("JavaUtilDate")` because it's not possible use differente Date API.
* Fixes `EqualsGetClass` warns
This commit fix all `EqualsGetClass` warns given by ErrorProne in the `gson/src/test.*` path.
I have rewrite the `equals()` methods to use `instanceof`
* Replaces pattern matching for instanceof with casts
* Fixes `JdkObsolete` warns
This commit fix all `JdkObsolete` warns given by ErrorProne in the `gson/src/test.*` path.
In some cases I have replaced the obsolete JDK classes with the newest alternatives. In other cases, I have added the `@SuppressWarnings("JdkObsolete")`
* Fixes `ClassCanBeStatic` warns
This commit fix all `ClassCanBeStatic` warns given by ErrorProne in the `gson/src/test.*` path.
I have added the `static` keyword, or I have added `@SuppressWarnings("ClassCanBeStatic")`
* Fixes `UndefinedEquals` warns
This commit fix all `UndefinedEquals` warns given by ErrorProne in the `gson/src/test.*` path.
I have added `@SuppressWarnings("UndefinedEquals")` or fixed the asserts
Note: In this commit I have also renamed a test from `testRawCollectionDeserializationNotAlllowed` to `testRawCollectionDeserializationNotAllowed`
* Fixes `GetClassOnEnum` warns
This commit fix all `GetClassOnEnum` warns given by ErrorProne in the `gson/src/test.*` path.
I have replaced the `.getClass()` with `.getDeclaringClass()`
* Fixes `ImmutableEnumChecker` warns
This commit fix all `ImmutableEnumChecker` warns given by ErrorProne in the `gson/src/test.*` path.
I have added the `final` keyword, or I have added the `@SuppressWarnings("ImmutableEnumChecker")` annotation
* Fixes `StaticAssignmentOfThrowable` warns
This commit fix all `StaticAssignmentOfThrowable` warns given by ErrorProne in the `gson/src/test.*` path.
* Fixes `AssertionFailureIgnored` warns
This commit fix all `AssertionFailureIgnored` warns given by ErrorProne in the `gson/src/test.*` path.
I have added the `@SuppressWarnings("AssertionFailureIgnored")` annotation
* Fixes `ModifiedButNotUsed` warns
This commit fix all `ModifiedButNotUsed` warns given by ErrorProne in the `gson/src/test.*` path.
I have added the `@SuppressWarnings("ModifiedButNotUsed")` annotation
* Fixes `MissingSummary` warns
This commit fix all `MissingSummary` warns given by ErrorProne in the `gson/src/test.*` path.
I have remove the Javadoc `@author`
* Fixes `FloatingPointLiteralPrecision` warns
This commit fix all `FloatingPointLiteralPrecision` warns given by ErrorProne in the `gson/src/test.*` path.
I have added the `@SuppressWarnings("FloatingPointLiteralPrecision")` annotation
* Fixes `StringSplitter` warns
This commit fix all `StringSplitter` warns given by ErrorProne in the `gson/src/test.*` path.
I have replaced the `String.split(...)` with `Splitter`
* Fixes `EmptyCatch` warns
This commit fix all `EmptyCatch` warns given by ErrorProne in the `gson/src/test.*` path.
* Fixes `UnicodeEscape` warns
This commit fix all `UnicodeEscape` warns given by ErrorProne in the `gson/src/test.*` path.
* Fixes `EmptyBlockTag` warns
This commit fix all `EmptyBlockTag` warns given by ErrorProne in the `gson/src/test.*` path.
* Fixes `LongFloatConversion` warns
This commit fix all `LongFloatConversion` warns given by ErrorProne in the `gson/src/test.*` path.
* Fixes `LongDoubleConversion` warns
This commit fix all `LongDoubleConversion` warns given by ErrorProne in the `gson/src/test.*` path.
* Fixes `TruthAssertExpected` warns
This commit fix all `TruthAssertExpected` warns given by ErrorProne in the `gson/src/test.*` path.
* Fixes `UnusedMethod` warns
This commit fix all `UnusedMethod` warns given by ErrorProne in the `gson/src/test.*` path.
* Fixes `UnusedTypeParameter` warns
This commit fix all `UnusedTypeParameter` warns given by ErrorProne in the `gson/src/test.*` path.
* Fixes `CatchFail` warns
This commit fix all `CatchFail` warns given by ErrorProne in the `gson/src/test.*` path.
* Fixes `MathAbsoluteNegative` warns
This commit fix all `MathAbsoluteNegative` warns given by ErrorProne in the `gson/src/test.*` path.
* Fixes `LoopOverCharArray` warns
This commit fix all `LoopOverCharArray` warns given by ErrorProne in the `gson/src/test.*` path.
`toCharArray` allocates a new array, using `charAt` is more efficient
* Fixes `HidingField` warns
This commit fix all `HidingField` warns given by ErrorProne in the `gson/src/test.*` path.
* Implements code review feedback
* Implements code review feedback
This commit implements some other code review feedback
* Enable ErrorProne in `extra`
Thi commit removes the `.*extras/src/test.*` path from the `-XepExcludedPaths` parameter of ErrorProne.
* Fix the `JavaUtilDate` warns
This commit fix all `JavaUtilDate` warns given by ErrorProne in the `extras/src/test.*` path.
* Implements code review feedback
* Removes redundant new-line
* Implements code review feedback
* Adds `JDK11` to run test with `--release 11`
* Revert "Adds `JDK11` to run test with `--release 11`"
This reverts commit a7cca386098ae847a10a31c09c3ab9b11eee5920.
* BoundField.write memory optimization
Declare and initialize the type adapter used for writing BoundFields outside of the anonymous class to ensure that a new TypeAdapterRuntimeTypeWrapper is not constructed each time a BoundField is written. This type adapter is only initialized if the BoundField will be used for serialization.
* Avoid confusing nullness-analysis tools
* Adds a javadoc summary to the methods in the `SerializedName` annotation
Fixes the `MissingSummary` warn given by ErrorProne
* Adds a javadoc summary to the methods of the `ExclusionStrategy` annotation
Fixes the `MissingSummary` warn given by ErrorProne
* Adds a javadoc summary to `getDeclaringClass()` and `getName()` methods of the `FieldAttributes` class
Fixes the `MissingSummary` warn given by ErrorProne
* Adds a javadoc summary to `getMajorJavaVersion()` and `isJava9OrLater()` methods of the `JavaVersion` class
Fixes the `MissingSummary` warn given by ErrorProne
* Adds a comment in the empty catch block of the `AccessChecker:101` class
Fixes the `EmptyCatch` warn given by ErrorProne
* Adds a comment in the empty catch block of the `DefaultDateTypeAdapter:158` class
Fixes the `EmptyCatch` warn given by ErrorProne
* Adds a comment in the empty catch blocks of the `UnsafeAllocator:(67|92|113)` class
Fixes the `EmptyCatch` warn given by ErrorProne
* Adds a comment in the empty catch block of the `DateTypeAdapter:85` class
Fixes the `EmptyCatch` warn given by ErrorProne
* Fixes javadoc param of the `deserialize(...)` method of the `JsonDeserializer` interface
Fixes the `InvalidParam` warn given by ErrorProne
* Adds a charset `StandardCharsets.UTF_8` in the `resourceToString()` method of the `ParseBenchmark` class
Fixes the `DefaultCharset` warn given by ErrorProne
* Fixes a typo
* Implements review feedback
* Adds blank line before @ tag.
* Fix `OperatorPrecedence` warn in `JsonWriter#close`
* Fix `ReferenceEquality` warn in `LinkedTreeMap#replaceInParent`
* Fix `UnnecessaryParentheses` warn in `LinkedTreeMap#replaceInParent`
* Fix `ReferenceEquality` warn in `LinkedTreeMap#hasNext`
* Fix `ReferenceEquality` warn in `LinkedTreeMap#nextNode`
* Adds `error_prone_annotations` to the `pom.xml` of `gson`
* Fix `InlineMeSuggester` warns in `JsonParser`
* Fix `UnnecessaryParentheses` warns in `ConstructorConstructor#newDefaultImplementationConstructor`
* Fix `ThreadLocalUsage` warn in `Gson`
* Fix `JdkObsolete` warn in `GsonBuilder`
* Fix `ReferenceEquality` warn in `LazilyParsedNumber#equals`
* Fix `OperatorPrecedence` warn in `TreeTypeAdapter#create`
* Fix `OperatorPrecedence` warn in `ArrayTypeAdapter`
* Fix `UnnecessaryParentheses` warn in `TypeAdapters`
* Adds `-XepExcludedPaths` flag to ErrorProne plugin to exclude tests and proto path
* Fix `ClassNewInstance` warn in `InterceptorAdapter`
* Fix `ThreadLocalUsage` warn in `GraphAdapterBuilder`
* Fix `JdkObsolete` warn in `GraphAdapterBuilder`
* Revert "Adds `error_prone_annotations` to the `pom.xml` of `gson`"
This reverts commit 14af14dfa23b46a54f4855a70ccf2b0a2cdc3e3f.
* Revert "Fix `InlineMeSuggester` warns in `JsonParser`"
This reverts commit 095bfd517e06510e4cc9cc6b1aac58ad9bf3038a.
* Adds `@SuppressWarnings("ThreadLocalUsage")`
* Fix `OperatorPrecedence` in `JsonWriter`
* Revert "Fix `ReferenceEquality` warn in `LinkedTreeMap#nextNode`"
This reverts commit 387746c7f7e3d0943c8f80501f5d9c3710f4862e.
* Adds `@SuppressWarnings("ReferenceEquality")`
* Adds `guava-testlib` to the gson `pom.xml`
* `@SuppressWarnings("TruthSelfEquals")` removed to use `EqualsTester()`
* Add settings for kind of newline to use
* Fix amp in javadoc
* Fixing link in javadoc
* Doc: use JSON instead of Json
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* PR Feedback: Objects.requireNonNull
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* PR Feedback: $next-version$, don't hardcode
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* s/testNewlineLF/testNewlineLf/
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Implement PR feedback
* Round two of review
* Restore copyright year, no reason to update
* Rename OS named enum values to CR and LF
* Add javadoc to NewlineStyle.getValue()
* Implement PR feedback, round 2
* Fix typo
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* No need for line break
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Shorter, cleaner doc
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Using a FormattingStyle for pretty print
* Fix Junit4 and Truth after merge from master
* Implement review feedback
* Double backslash in message
---------
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
* Remove EOFException special casing of JsonStreamParser.next()
The previous behavior violated the Iterator contract where for
`JsonStreamParser("[")` a call to `hasNext()` would return true,
but `next()` would throw a NoSuchElementException.
* Fix incorrect documented thrown exception type for JsonStreamParser
* 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
* 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