Commit Graph

1445 Commits

Author SHA1 Message Date
Marcono1234 66d9621ce8
Adjust Record adapter and extend test coverage (#2224)
* 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
2022-10-22 09:01:56 -07:00
Marcono1234 954d526af4
Add `JsonArray.asList` and `JsonObject.asMap` view methods (#2225)
* Add `JsonArray.asList` and `JsonObject.asMap` view methods

* Address review comments
2022-10-16 12:30:49 -07:00
Éamonn McManus 86c35bba30
Small adjustments to the new record code. (#2219)
* 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.
2022-10-12 14:24:36 -07:00
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
Marcono1234 8451c1fa63
Fix TypeAdapterRuntimeTypeWrapper not detecting reflective TreeTypeAdapter and FutureTypeAdapter (#1787)
* 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>
2022-10-10 16:10:48 -07:00
Marcono1234 5269701679
Improve `JsonReader.skipValue()` (#2062)
* 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>
2022-10-10 07:51:36 -07:00
Marcono1234 e614e71ee4
Clarify in documentation that Gson might cache strategy results (#2215)
* Clarify in documentation that Gson might cache strategy results

* Improve wording; mention that adapter factory results are cached as well
2022-10-04 09:01:55 -07:00
Marcono1234 3e3266cf48
Perform numeric conversion for primitive numeric type adapters (#2158)
* 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
2022-10-04 07:22:26 -07:00
Marcono1234 796193d032
Improve versioning support documentation and validate version (#2214) 2022-10-02 16:38:43 -07:00
Marcono1234 28609089fa
Add Javadoc since tags for previously added elements (#2211) 2022-10-01 15:58:26 -07:00
BillyGalbreath 47668fad57
Fix typo in GsonBuilder Javadoc (#2213) 2022-10-01 15:57:16 -07:00
kb1000 9c9cafcf9d
Only create one UnsafeAllocator instance (#2196)
* Only create one UnsafeAllocator instance

* Move checkInstantiable to ConstructorConstructor
2022-09-29 15:59:47 -07:00
Marcono1234 5253ddbde0
Follow-up for record test build changes (#2207) 2022-09-27 23:02:15 -07:00
Éamonn McManus 441406cc78
Add a currently-failing test for Java records and `@Ignore` it. (#2203)
* Add a currently-failing test for Java records and `@Ignore` it.

Also do the Maven gymastics required to ensure that this test only runs on Java
versions ≥17. (It would also work on Java 16, but 17 is all we have in the CI.)

Fix some compilation problems I saw when running locally, which for some reason
don't show up in the CI.

* Suppress some new lint options that trigger `-Werror`.
We may fix these later. (Every test will need an explicit constructor!)

* Select Java version with maven.compiler.release and maven.compiler.testRelease.

Use `assumeNotNull` rather than an if-statement.

* Specify <release>11</release> for javadoc.

* Restore the @see for AccessibleObject.
2022-09-27 12:32:40 -07: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 6b9db2e449
Add Gson.fromJson(..., TypeToken) overloads (#1700)
* Add Gson.fromJson(..., TypeToken) overloads

Previously only Gson.fromJson(..., Type) existed which is however not
type-safe since the generic type parameter T used for the return type is
not bound.
Since these methods are often used in the form
  gson.fromJson(..., new TypeToken<...>(){}.getType())
this commit now adds overloads which accept a TypeToken and are therefore
more type-safe.

Additional changes:
- Fixed some grammar mistakes
- Added javadoc @see tags
- Consistently write "JSON" in uppercase
- More precise placement of @SuppressWarnings("unchecked")

* Add to Gson.fromJson javadoc that JSON is fully consumed

The newly added documentation deliberately does not state which exception
is thrown because Gson.assertFullConsumption could throw either a
JsonIOException or a JsonSyntaxException.

* Remove unnecessary wrapping and unwrapping as TypeToken in Gson.fromJson

Since the actual implementation of Gson.fromJson is TypeToken based, the
TypeToken variant overloads are now the "main" implementation and the other
overloads delegate to them.
Previously the Type variant overloads were the "main" implementation which
caused `TypeToken.getType()` followed by `TypeToken.get(...)` when the
TypeToken variant overloads were used.

* Trim source code whitespaces

* Fix Gson.fromJson(JsonReader, Class) not casting read Object

To be consistent with the other Gson.fromJson(..., Class) overloads the
method should cast the result.

* Replace User Guide link in Gson documentation

* Remove more references to fromJson(..., Type)

* Extend documentation for fromJson(JsonReader, ...)

* Replace some TypeToken.getType() usages

* Address feedback; improve documentation

* Remove fromJson(JsonReader, Class) again

As noticed during review adding this method is source incompatible.
2022-09-19 06:47:11 -07:00
Johannes Frohnmeyer f6e2bd0fb0
Fix tests by removing broken ones 2022-09-14 19:55:35 +02:00
Johannes Frohnmeyer ded8d1c79f
No module 2022-09-14 19:44:09 +02:00
Johannes Frohnmeyer 8ec31281a7
Try fixing 2022-09-14 19:41:29 +02:00
Johannes Frohnmeyer 67402b1acf
Attempt to fix pom by replacing it with the current upstream 2022-09-14 19:31:32 +02:00
Johannes Frohnmeyer f47c21fce7
Remove one deprecated method 2022-09-14 19:24:15 +02:00
Johannes Frohnmeyer ce02cb3bc1
Merge remote-tracking branch 'origin/master'
# Conflicts:
#	gson/pom.xml
#	gson/src/main/java/com/google/gson/Gson.java
#	gson/src/main/java/com/google/gson/GsonBuilder.java
#	gson/src/main/java/com/google/gson/internal/bind/ArrayTypeAdapter.java
#	gson/src/main/java/com/google/gson/stream/JsonWriter.java
#	gson/src/test/java/com/google/gson/functional/ArrayTest.java
#	gson/src/test/java/com/google/gson/functional/MapTest.java
#	pom.xml
2022-09-14 19:20:24 +02:00
Deepti M a733150cfa
updated JsonDeserializer example (#2192)
* fixed json deserializer example

* correcting the json

* updated per review

* updated per review

* updated per review
2022-09-12 10:14:05 -07:00
Marcono1234 847d7f6638
Improve documentation (#2193)
* Improve JsonElement subclasses javadoc and add tests

* Slightly improve JsonSerializer and JsonDeserializer javadoc

* Improve ReflectionAccessTest failure message

* Improve documentation regarding field and class exclusion
2022-09-09 07:32:55 -07:00
Marcono1234 2266ccdd67
Remove usage of oss-parent Maven parent and update ReleaseProcess.md (#2159)
The oss-parent configuration has been applied manually to the root pom.xml,
except that now newer plugin versions are used for source and javadoc JAR
creation, and for GPG signing.

This required some reordering of the plugins for the gson module to make
sure they are executed in the correct order. Otherwise this would cause
failures for javadoc:jar.
2022-09-06 16:26:53 -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
Marcono1234 325f37cd6b
Verify that JsonTreeReader and JsonTreeWriter override all methods (#2181)
* Verify that JsonTreeReader and JsonTreeWriter override all methods

If those classes do not override one of the JsonReader or JsonWriter methods
the user might encounter an AssertionError.

* Address review feedback
2022-08-23 14:19:47 -07:00
Marcono1234 7f77ad4ff6
Replace `$Gson$Preconditions.checkNotNull` with `Objects.requireNonNull` (#2180)
* Replace $Gson$Preconditions.checkNotNull with Objects.requireNonNull

* Add back checkNotNull
2022-08-22 07:22:32 -07:00
Marcono1234 b0b6834157
Mention that GsonBuilder.registerTypeAdapter makes (de-)serializers null-safe (#1704) 2022-08-22 06:55:31 -07:00
Marcono1234 5bebf970d1
Fix changes to GsonBuilder affecting existing Gson instances (#1815)
Previously when a GsonBuilder had created a Gson instance and was afterwards
reused and different type adapters were added, new GsonBuilder instances
obtained from the previous Gson instance through Gson.newBuilder() would have
been affected by the GsonBuilder changes.

This commit fixes this and additionally adds some more unit tests.
2022-08-22 06:49:48 -07:00
Marcono1234 51a72b463b
Make JsonElement conversion methods more consistent and fix javadoc (#2178)
* Make JsonElement conversion methods more consistent and fix javadoc

* Address some review comments
2022-08-21 13:29:40 -07:00
Marcono1234 26be941575
Throw UnsupportedOperationException when JsonWriter.jsonValue is not supported (#1651) 2022-08-21 08:49:32 -07:00
Marcono1234 b84b2218f2
Add null checks for GsonBuilder methods (#2179) 2022-08-20 13:16:35 -07:00
Marcono1234 18b9ba407d
Improve GsonTest.testGetAdapter_Concurrency (#2177)
Makes the test implementation more reliable to prevent flaws in the test
setup causing spurious test success.
2022-08-19 10:25:20 -07:00
Marcono1234 5e1005ea27
Disallow `JsonObject` `Entry.setValue(null)` (#2167)
* Disallow JsonObject Entry.setValue(null)

* Adjust comments in JsonObjectTest
2022-08-18 13:10:43 -07:00
Lorenz Nickel 53234aa351
Add test for JsonArray.isEmpty() (#2173) 2022-08-08 08:38:56 -07:00
Marcono1234 6fc1c8f7f1
Fix `TypeAdapter.toJson` throwing AssertionError for custom IOException (#2172)
* Fix TypeAdapter.toJson throwing AssertionError for custom IOException

* Add throws javadoc tag for TypeAdapter methods
2022-08-08 08:19:44 -07:00
Marcono1234 d53b3ea84a
Clarify doc about non-finite numbers for non-lenient JsonReader (#1723) 2022-08-08 06:40:07 -07:00
Marcono1234 a4bc6c17d7
Fix JsonTreeReader throwing wrong exception type for non-finite doubles (#1782)
Follow-up for #1767
2022-08-08 06:39:29 -07:00
Marcono1234 f7cefcb426
Fix JsonWriter documentation regarding top-level value (#1766)
* Fix JsonReader / JsonWriter documentation regarding top-level value

RFC 7159 allows any top-level value (not only arrays or objects) [0],
however when #773 added this functionality it appears the author forgot
to update the documentation of these classes.

[0] https://tools.ietf.org/html/rfc7159#appendix-A
> Changed the definition of "JSON text" so that it can be any JSON
> value, removing the constraint that it be an object or array.

* Fix missing space
2022-08-07 16:24:37 -07:00
Marcono1234 9eb04414c0
Improve InternationalizationTest (#1705)
* Improve InternationalizationTest

- Remove "raw" tests since after compiling they are the same as the one with
  escape sequences
- Add tests for supplementary code points (> \uFFFF)

* Improve variable names, fix incorrect escape sequences
2022-08-07 16:00:35 -07:00
James 9868957862
Fix typo (#1246) 2022-08-07 15:43:37 -07:00
Marcono1234 390385e382
Clarify that `GsonBuilder.setExclusionStrategies` does not replace existing ones (#2168)
* Clarify that `GsonBuilder.setExclusionStrategies` does not replace existing ones

* Fix punctuation
2022-08-06 10:01:37 -07:00
Marcono1234 246270e02c
Convert null to JsonNull for `JsonArray.set` (#2170)
* Convert null to JsonNull for `JsonArray.set`

All other methods perform the same implicit conversion.

* Mention null handling in JsonObject documentation
2022-08-06 09:57:00 -07:00
bufistov 46b97bf156
Fixed nullSafe usage. (#1555)
The JsonSerializer/Deserializer adapters used to ignore this attribute
which result in inconsistent behaviour for annotated adapters.

Fixes #1553

Signed-off-by: Dmitry Bufistov <dmitry@midokura.com>

Co-authored-by: Dmitry Bufistov <dmitry@midokura.com>
2022-08-05 07:33:05 -07:00
Marcono1234 98f2bbf4c1
Validate `TypeToken.getParameterized` arguments (#2166) 2022-08-05 06:59:38 -07:00
Marcono1234 0b6a7bf7d9
Deprecate JsonElement constructor (#1761)
* Deprecate JsonElement constructor

Creating custom JsonElement subclasses is discouraged.

* Improve test and documentation

* Improve JsonTreeReaderTest, adjust deprecation comments
2022-08-04 10:32:30 -07:00
Marcono1234 a1d2ebc8b5
Fix #1702: Gson.toJson creates CharSequence which does not implement toString (#1703)
* Gson.toJson creates CharSequence which does not implement toString

* Improve Streams.AppendableWriter.CurrentWrite test

* Make setChars package-private
2022-08-03 14:25:12 -07:00
Marcono1234 4552db2630
Prefer existing adapter for concurrent `Gson.getAdapter` calls (#2153)
Additionally fail fast for null as type (previous null support was broken
and would have thrown NullPointerException further below anyways).
2022-08-01 10:59:04 -07:00
Marcono1234 a45c55739f
Improve ArrayTypeAdapter for Object[] (#1716)
* Improve ArrayTypeAdapter for Object[]

* Fix typo in test method names
2022-07-31 14:49:02 -07:00
Marcono1234 5f2513a407
Improve AppendableWriter performance (#1706)
* Improve AppendableWriter performance

Override methods which by default create char arrays or convert
CharSequences to Strings.
This is not necessary for AppendableWriter because it can directly
append these values to the Appendable delegate.

* Add test for Streams.writerForAppendable
2022-07-31 14:46:43 -07:00
Éamonn McManus ca22b68008 [maven-release-plugin] prepare for next development iteration 2022-07-31 14:25:34 -07:00
Éamonn McManus bb9a1f255a [maven-release-plugin] prepare release gson-parent-2.9.1 2022-07-31 14:25:32 -07:00
Marcono1234 893a7e1c5c
Fix malformed JsonElement.getAsBigDecimal() javadoc (#1772) 2022-07-31 14:08:24 -07:00
Marcono1234 6d2557d5d1
Remove unused package-private FieldAttributes methods (#2162) 2022-07-29 10:10:54 -07:00
dependabot[bot] 924c496b95
Bump maven-resources-plugin from 3.2.0 to 3.3.0 (#2157)
Bumps [maven-resources-plugin](https://github.com/apache/maven-resources-plugin) from 3.2.0 to 3.3.0.
- [Release notes](https://github.com/apache/maven-resources-plugin/releases)
- [Commits](https://github.com/apache/maven-resources-plugin/compare/maven-resources-plugin-3.2.0...maven-resources-plugin-3.3.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-resources-plugin
  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>
2022-07-25 20:37:16 -07:00
Marcono1234 503c20bb39
Rename ReflectiveTypeAdapterFactory field inclusion check method (#2121) 2022-07-21 11:53:52 -07:00
Marcono1234 cbc0af867b
Improve lenient mode documentation (#2122) 2022-06-28 09:48:05 -07:00
Marcono1234 2d01d6a20f
Make `Object` and `JsonElement` deserialization iterative (#1912)
* Make Object and JsonElement deserialization iterative

Often when Object and JsonElement are deserialized the format of the JSON
data is unknown and it might come from an untrusted source. To avoid a
StackOverflowError from maliciously crafted JSON, deserialize Object and
JsonElement iteratively instead of recursively.

Concept based on 51fd2faab7
But implementation is not based on it.

* Improve imports grouping

* Address review feedback
2022-06-22 17:42:19 -07:00
Nathan Herring d2aee6502b
Add explicit support for floats in JsonTreeWriter. (#2132)
Follow-up to comments on #2130, which introduced a new override which was not overridden by `JsonTreeWriter`. Also tweaks the doccomments for `float`, `double` and `Number` variants of `JsonWriter.value`.

Supplement to the fix for #1127.
2022-06-21 09:50:07 -07:00
dependabot[bot] 08d4572fc4
Bump proguard-maven-plugin from 2.5.3 to 2.6.0 (#2136)
Bumps [proguard-maven-plugin](https://github.com/wvengen/proguard-maven-plugin) from 2.5.3 to 2.6.0.
- [Release notes](https://github.com/wvengen/proguard-maven-plugin/releases)
- [Changelog](https://github.com/wvengen/proguard-maven-plugin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/wvengen/proguard-maven-plugin/commits)

---
updated-dependencies:
- dependency-name: com.github.wvengen:proguard-maven-plugin
  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>
2022-06-20 17:01:20 -07:00
Marcono1234 57225c6741
Fail when parsing invalid local date (#2134)
* Fail when parsing invalid local date

* Improve invalid date tests
2022-06-16 13:47:57 -07:00
Nathan Herring 96ab171eb4
Add explicit support for floats in JsonWriter. (#2130)
This avoids floats being treated as doubles and having an unwarranted level of precision.

Fixes #1127.
2022-06-08 15:04:42 -07:00
dependabot[bot] 15b9fa9c31
Bump maven-surefire-plugin from 3.0.0-M6 to 3.0.0-M7 (#2128)
Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.0.0-M6 to 3.0.0-M7.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.0.0-M6...surefire-3.0.0-M7)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-surefire-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-08 07:21:23 -07:00
dependabot[bot] d1fce29b27
Bump bnd-maven-plugin from 6.2.0 to 6.3.1 (#2129)
Bumps [bnd-maven-plugin](https://github.com/bndtools/bnd) from 6.2.0 to 6.3.1.
- [Release notes](https://github.com/bndtools/bnd/releases)
- [Changelog](https://github.com/bndtools/bnd/blob/master/docs/ADDING_RELEASE_DOCS.md)
- [Commits](https://github.com/bndtools/bnd/compare/6.2.0...6.3.1)

---
updated-dependencies:
- dependency-name: biz.aQute.bnd:bnd-maven-plugin
  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>
2022-06-08 07:21:02 -07:00
Johannes Frohnmeyer 379b2563b2
Use deferred comment serialization to fix prominent issues 2022-06-04 11:59:48 +02:00
Johannes Frohnmeyer 031f729d32
Fix Json5 test 2022-05-17 21:40:18 +02:00
Johannes Frohnmeyer 41cafc0987
Remove references to deleted test 2022-05-17 21:35:52 +02:00
Johannes Frohnmeyer dc4e61ac7b
Several breaking changes 2022-05-17 21:20:10 +02:00
Johannes Frohnmeyer ccf30b23e8 newline before comment 2022-05-17 06:15:12 +00:00
Johannes Frohnmeyer 35241fc7b2
Add comment support 2022-05-12 23:23:14 +02:00
Johannes Frohnmeyer 9d7fd891ee
Merge branch 'allow_duplicate_map_key'
# Conflicts:
#	gson/src/main/java/com/google/gson/GsonBuilder.java
#	gson/src/test/java/com/google/gson/GsonTest.java
2022-05-12 22:54:17 +02:00
Marcono1234 b1c399fd62
Improve `TypeToken` creation validation (#2072)
* Add comments regarding multiple bounds of wildcard

* Remove WildcardType check in getCollectionElementType

The returned Type is never a wildcard due to the changes made to getSupertype
by commit b1fb9ca9a1.

* Remove redundant getRawType call from MapTypeAdapterFactory

getRawType(TypeToken.getType()) is the same as calling TypeToken.getRawType().

* Make TypeToken members private

* Remove incorrect statement about TypeToken wildcards

It is possible to use wildcards as part of the type argument, e.g.:
`new TypeToken<List<? extends CharSequence>>() {}`

* Only allow direct subclasses of TypeToken

Previously subclasses of subclasses (...) of TypeToken were allowed which
can behave incorrectly when retrieving the type argument, e.g.:

  class SubTypeToken<T> extends TypeToken<Integer> {}
  new SubTypeToken<String>() {}.getType()

This returned `String` despite the class extending TypeToken<Integer>.

* Throw exception when TypeToken captures type variable

Due to type erasure the runtime type argument for a type variable is not
available. Therefore there is no point in capturing a type variable and it
might even give a false sense of type-safety.

* Make $Gson$Types members private

* Rename $Gson$Types.getGenericSupertype parameter

Rename the method parameter to match the documentation of the method and
to be similar to getSupertype(...).

* Improve tests and handle raw TypeToken supertype better

* Make some $Gson$Types members package-private again to prevent synthetic accessors

* Remove TypeToken check for type variable

As mentioned in review comments, there are cases during serialization where
usage of the type variable is not so problematic (but still not ideal).
2022-04-19 08:20:58 -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
dependabot[bot] f79ea208b1
Bump maven-surefire-plugin from 3.0.0-M5 to 3.0.0-M6 (#2101)
Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.0.0-M5 to 3.0.0-M6.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.0.0-M5...surefire-3.0.0-M6)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-surefire-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-04-03 20:08:33 -07:00
dependabot[bot] 9125653278
Bump bnd-maven-plugin from 6.1.0 to 6.2.0 (#2084)
Bumps [bnd-maven-plugin](https://github.com/bndtools/bnd) from 6.1.0 to 6.2.0.
- [Release notes](https://github.com/bndtools/bnd/releases)
- [Changelog](https://github.com/bndtools/bnd/blob/master/docs/ADDING_RELEASE_DOCS.md)
- [Commits](https://github.com/bndtools/bnd/compare/6.1.0...6.2.0)

---
updated-dependencies:
- dependency-name: biz.aQute.bnd:bnd-maven-plugin
  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>
2022-02-28 07:40:22 -08:00
Marcono1234 81bb6d1dec
Remove `gson/build.gradle` (#2081)
Follow-up for be0a1f4ff7
2022-02-23 11:18:56 -08:00
Marcono1234 b5343ba96c
Add tests for enum constant toString() reading (#2080) 2022-02-21 14:53:59 -08:00
Mahmut H. Kocas 7ee3e2787f
Parsing Map<Enum,Obj> - 501 (#1950)
* Added parsing support for enum that has overridden toString() method.

* Fix a tiny formatting problem

* Fixed formatting issue

Co-authored-by: Éamonn McManus <emcmanus@google.com>
2022-02-21 13:11:43 -08: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 d19e9fe0af
Improve Maven build and GitHub Maven workflow (#2079)
* Fix consecutive Maven builds failing without performing `clean`

By default moditect-maven-plugin refuses to overwrite the JAR file it
generated in a previous run.

* Make GitHub Maven build workflow detect Javadoc issues
2022-02-16 12:51:08 -08:00
Éamonn McManus e58db43f57 [maven-release-plugin] prepare for next development iteration 2022-02-11 11:13:24 -08:00
Éamonn McManus b6acf1178a [maven-release-plugin] prepare release gson-parent-2.9.0 2022-02-11 11:13:22 -08:00
Marcono1234 47dea2eefc
Improve error message when abstract class cannot be constructed (#1814) 2022-02-04 14:19:47 -08:00
Marcono1234 565b7a198e
Support EnumMap deserialization (#2071) 2022-02-04 07:20:32 -08:00
Marcono1234 e2e851c9bc
Add LazilyParsedNumber default adapter (#2060)
* Add LazilyParsedNumber default adapter

* Validate JsonWriter.value(Number) argument

* Fix incorrect JSON number pattern, extend tests
2022-01-28 11:26:28 -08:00
Marcono1234 710a76c8b8
Fix JsonReader.hasNext() returning true at end of document (#2061) 2022-01-27 15:59:50 -08:00
Éamonn McManus 26e08fe742
Fix a mistaken use of StringBuilder('#'). (#2052) 2022-01-12 08:58:30 -08:00
Marcono1234 73216b2ad7
Add more `Gson` default constants to be used by `GsonBuilder` (#2051) 2022-01-12 07:07:55 -08:00
Marcono1234 d38e397421
Fix ObjectTest not restoring default Locale (#2050) 2022-01-10 07:18:42 -08:00
Marcono1234 6b96a389cc
Put `module-info.class` into Multi-Release JAR folder (#2013)
* Put module-info.class into Multi-Release JAR folder

Uses ModiTect to place module-info.class under Multi-Release JAR folder
`META-INF/versions/9`.

* Adjust pom.xml to drop support for Java 6

* Change doclint setting

All Javadoc errors have been solved previously; doclint can now be enabled
without causing build failures.

* Improve README Java requirements
2022-01-01 12:44:39 -08:00
Marcono1234 dc28951fa7
Change target Java version to 7 (#2043)
* Change target Java version to 7

* Document Gson requirements

* Add package-info.java for `stream` package
2021-12-31 07:20:29 -08:00
Marcono1234 615c8835d3
Add `GsonBuilder.disableJdkUnsafe()` (#1904)
* Add GsonBuilder.disableJdkUnsafe()

* Address review feedback
2021-12-30 15:08:18 -08:00
Marcono1234 97938283a7
Remove explicit ProGuard plugin dependencies (#2041)
Explicitly specifying dependencies only seems to be necessary when using
`<proguardVersion>` config element to override version (and even that might
not be necessary; only adding explicit dependencies might suffice). However,
when omitting it, plugin uses a recent ProGuard version on its own.
2021-12-28 09:56:49 -08:00
Marcono1234 abd2191b0e
Add READMEs to Maven modules (#2039)
* Add READMEs to Maven modules

* Address feedback
2021-12-27 10:17:41 -08:00
Marcono1234 6ffcdf3029
Fix Javadoc warnings and errors (#2040) 2021-12-26 15:30:21 -08:00
dependabot[bot] 1dd150e86f
Bump proguard-maven-plugin from 2.5.2 to 2.5.3 (#2037)
Bumps [proguard-maven-plugin](https://github.com/wvengen/proguard-maven-plugin) from 2.5.2 to 2.5.3.
- [Release notes](https://github.com/wvengen/proguard-maven-plugin/releases)
- [Changelog](https://github.com/wvengen/proguard-maven-plugin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/wvengen/proguard-maven-plugin/commits)

---
updated-dependencies:
- dependency-name: com.github.wvengen:proguard-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-20 09:37:56 -08:00
dependabot[bot] 4b3127f669
Bump proguard-maven-plugin from 2.5.1 to 2.5.2 (#2034)
Bumps [proguard-maven-plugin](https://github.com/wvengen/proguard-maven-plugin) from 2.5.1 to 2.5.2.
- [Release notes](https://github.com/wvengen/proguard-maven-plugin/releases)
- [Changelog](https://github.com/wvengen/proguard-maven-plugin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/wvengen/proguard-maven-plugin/commits)

---
updated-dependencies:
- dependency-name: com.github.wvengen:proguard-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-16 14:36:39 -08:00
dependabot[bot] cdf8ab5213
Bump bnd-maven-plugin from 6.0.0 to 6.1.0 (#2025)
Bumps [bnd-maven-plugin](https://github.com/bndtools/bnd) from 6.0.0 to 6.1.0.
- [Release notes](https://github.com/bndtools/bnd/releases)
- [Changelog](https://github.com/bndtools/bnd/blob/master/docs/ADDING_RELEASE_DOCS.md)
- [Commits](https://github.com/bndtools/bnd/compare/6.0.0...6.1.0)

---
updated-dependencies:
- dependency-name: biz.aQute.bnd:bnd-maven-plugin
  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>
2021-12-09 13:34:38 -08:00
yixingz3 eaf9a0342d
feat: added UPPER_CASE_WITH_UNDERSCORES in FieldNamingPolicy (#2024) 2021-11-28 09:33:22 -08:00
Éamonn McManus 6e06bf0d89 Fix for an ArrayIndexOutOfBoundsException.
The `fillBuffer` method changes `pos`, so it is incorrect to cache
its previous value.
2021-11-11 14:12:44 -05:00
Marcono1234 b0595c595b
Fix failing to serialize Collection or Map with inaccessible constructor (#1902)
* Remove UnsafeReflectionAccessor

Revert #1218

Usage of sun.misc.Unsafe to change internal AccessibleObject.override field
to suppress JPMS warnings goes against the intentions of the JPMS and does not
work anymore in newer versions, see #1540.
Therefore remove it and instead create a descriptive exception when making a
member accessible fails. If necessary users can also still use `java` command
line flags to open external modules.

* Fix failing to serialize Collection or Map with inaccessible constructor

Also remove tests which rely on Java implementation details.

* Don't keep reference to access exception of ConstructorConstructor

This also avoids a confusing stack trace, since the previously caught
exception might have had a complete unrelated stack trace.

* Remove Maven toolchain requirement

* Address review feedback

* Add back test for Security Manager
2021-11-09 07:16:35 -08:00
Marcono1234 ca2ed748ba
Fix warnings (#2014)
* Fix warnings

* Address review feedback
2021-11-07 08:43:49 -08:00
Marcono1234 cc505e1b9f
Convert codegen, metrics and proto to Maven submodules (#2008)
* Convert codegen, metrics and proto to Maven submodules

* Fix import order
2021-11-07 08:42:08 -08:00
Marcono1234 a92bbf849c
Improve TreeTypeAdapter thread-safety (#1976)
* Improve TreeTypeAdapter thread-safety

Gson claims to be thread-safe so TreeTypeAdapter.delegate() might be
called by multiple threads. To guarantee that each thread sees a fully
constructed `delegate`, the field has to be `volatile`.

* Improve TreeTypeAdapter thread race comment
2021-11-01 15:13:08 -07:00
Marcono1234 deaa3a6cd9
Fix `Gson.newJsonWriter` ignoring lenient and HTML-safe setting (#1989)
* Improve Gson newJsonWriter and newJsonReader documentation

* Consider lenient and HTML-safe setting for Gson.newJsonWriter

* Remove empty line between imports
2021-11-01 15:11:10 -07:00
Marcono1234 e0de45ff69
Delete unused LinkedHashTreeMap (#1992)
Class seems to be unused since commit f29d5bc37b.
Gson currently only uses LinkedTreeMap.
2021-11-01 15:09:14 -07:00
Marcono1234 b4dab86b10
Make default adapters stricter; improve exception messages (#2000)
* Make default adapters stricter; improve exception messages

* Reduce scope of synchronized blocks

* Improve JsonReader.getPath / getPreviousPath Javadoc
2021-11-01 15:08:04 -07:00
Marcono1234 b3188c1132
Fix `FieldNamingPolicy.upperCaseFirstLetter` uppercasing non-letter (#2004) 2021-11-01 15:05:04 -07:00
Éamonn McManus 031db9d473
Update CHANGELOG.md for 2.8.9. (#2005)
* Update CHANGELOG.md for 2.8.9.

* Adjust snapshot version. Gson versions have three numbers.
2021-10-29 13:41:12 -07:00
Éamonn McManus 128586847b [maven-release-plugin] prepare for next development iteration 2021-10-29 12:58:56 -07:00
Éamonn McManus 6a368d89da [maven-release-plugin] prepare release gson-parent-2.8.9 2021-10-29 12:58:54 -07:00
Marcono1234 ba96d53bad
Fix missing bounds checks for JsonTreeReader.getPath() (#2001)
There are situations where the stack of JsonTreeReader contains a JsonArray
or JsonObject without a subsequent Iterator, for example after calling peek()
or nextName().
When JsonTreeReader.getPath() is called afterwards it therefore must not
assume that a JsonArray or JsonObject is always followed by an Iterator.

The only reason why this never caused an ArrayIndexOutOfBoundsException in
the past is because the stack has an even default size (32) so it would just
have read the next `null`.
However, if the stack had for example the default size 31, a user created a
JsonTreeReader for 16 JSON arrays nested inside each other, then called 15
times beginArray(), followed by peek() and getPath() the exception would
occur.
2021-10-25 12:14:41 -07:00
Jaroslav Tulach ca1df7f7e0
#1981: Optional OSGi bundle's dependency on sun.misc package (#1993)
* #1981: Avoid OSGi bundle's dependency on sun.misc package

* Specify optional dependency on sun.misc.Unsafe

* Adjusting the test to sun.misc import being optional

* Using Collections.list and for loop

* Let the fail message include name of package

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>

* Closing the input stream

* Dedicated assertSubstring method

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
2021-10-25 11:32:10 -07:00
Marcono1234 c54caf308c
Deprecate `Gson.excluder()` exposing internal `Excluder` class (#1986) 2021-10-25 11:28:16 -07:00
Marcono1234 e6fae590cf
Prevent Java deserialization of internal classes (#1991)
Adversaries might be able to forge data which can be abused for DoS attacks.
These classes are already writing a replacement JDK object during serialization
for a long time, so this change should not cause any issues.
2021-10-13 10:14:57 -07:00
Marcono1234 bda2e3d16a
Improve number strategy implementation (#1987)
* Fix GsonBuilder not copying number strategies from Gson

* Improve ToNumberPolicy exception messages
2021-10-11 16:14:47 -07:00
Marcono1234 cd748df712
Fix LongSerializationPolicy null handling being inconsistent with Gson (#1990)
Gson does not actually use the specified LongSerializationPolicy but instead
uses type adapters which emulate the behavior. However, previously Gson's
implementation did not match LongSerializationPolicy regarding null handling.

Because it is rather unlikely that LongSerializationPolicy has been used on
its own, this commit adjusts its implementation to match Gson's behavior
(instead of the other way around).
2021-10-11 12:34:32 -07:00
Lyubomyr Shaydariv fe30b85224
Support arbitrary Number implementation for Object and Number deserialization (#1290)
* Object and Number type adapters number deserialization can be configured

* Change wording of ToNumberStrategy documentation

* Use inline links in doc sparingly

If the element has already been linked before, don't create a link for
every subsequent occurrence.

See also (slightly dated)
https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html#inlinelinks

* Link to default to-number policies in ToNumberStrategy doc

* Reduce code duplication for deserializing Number

* Hide default factory constants of NumberTypeAdapter and ObjectTypeAdapter

This encapsulates the logic a little bit better.
Additionally refactored factory created by NumberTypeAdapter to only create
TypeAdapter once and then have factory reuse that adapter for better
performance.

Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
2021-10-08 17:09:43 -07:00
dependabot[bot] 7b9a283a7a
Bump bnd-maven-plugin from 5.3.0 to 6.0.0 (#1985)
Bumps [bnd-maven-plugin](https://github.com/bndtools/bnd) from 5.3.0 to 6.0.0.
- [Release notes](https://github.com/bndtools/bnd/releases)
- [Changelog](https://github.com/bndtools/bnd/blob/master/docs/ADDING_RELEASE_DOCS.md)
- [Commits](https://github.com/bndtools/bnd/commits/6.0.0)

---
updated-dependencies:
- dependency-name: biz.aQute.bnd:bnd-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-06 17:58:02 -07:00
dependabot[bot] b0f3237bb8
Bump proguard-maven-plugin from 2.4.0 to 2.5.1 (#1980)
Bumps [proguard-maven-plugin](https://github.com/wvengen/proguard-maven-plugin) from 2.4.0 to 2.5.1.
- [Release notes](https://github.com/wvengen/proguard-maven-plugin/releases)
- [Changelog](https://github.com/wvengen/proguard-maven-plugin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/wvengen/proguard-maven-plugin/commits)

---
updated-dependencies:
- dependency-name: com.github.wvengen:proguard-maven-plugin
  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>
2021-09-28 09:59:56 -07:00
Marcono1234 aa5554e69a
Don't exclude static local classes (#1969) 2021-09-17 18:12:47 -07:00
Marcono1234 f1f90313fc
Improve Maven build (#1964)
- Specify missing plugin versions
- Fix or suppress ProGuard notes and warnings
2021-09-17 17:19:50 -07:00
Nikita Novik 4f2aeaa288
Add license note to GSON POM file. (#1951)
* Add license note to GSON POM file.
2021-09-06 10:35:43 -07:00
Éamonn McManus c8f26dc907
Add missing calls when testing for exceptions. (#1948) 2021-08-31 15:03:45 -07:00
Éamonn McManus 1a2e58a42f
Remove an unused import. (#1947) 2021-08-31 14:55:07 -07:00
Simon Guerout 66fd2acdcf Fix formatting 2021-08-30 09:57:08 -07:00
Simon Guerout ac14b4c197 Make the nextJsonElement more robust
Add test cases
2021-08-30 09:57:08 -07:00
Simon Guerout 62a9702385 Improve the speed of the JSON_ELEMENT TypeAdapter when the object graph has already been turned into a JsonElement 2021-08-30 09:57:08 -07:00
Éamonn McManus 69173b02ea
Merge branch 'master' into optional-sql 2021-08-24 13:41:12 -07:00
Éamonn McManus b2f661166f [maven-release-plugin] prepare for next development iteration 2021-08-20 09:07:21 -07:00
Éamonn McManus b41030d3dc [maven-release-plugin] prepare release gson-parent-2.8.8 2021-08-20 09:07:19 -07:00
Éamonn McManus 9edaeb3b2e
Merge pull request #1909 from HiFromAjay/aj
Test cases for testing the exceptional behavior of JsonArray get... methods
2021-08-07 07:54:12 -07:00
HiFromAjay 01ab13f701 Remove unused imports [#1909, #1908] 2021-08-05 17:23:28 -06:00
Éamonn McManus df94ccdb48
Merge pull request #1925 from google/dependabot/maven/org.apache.maven.plugins-maven-resources-plugin-3.2.0
Bump maven-resources-plugin from 2.7 to 3.2.0
2021-08-05 06:28:52 -07:00
Éamonn McManus 80feb232b5
Merge pull request #1926 from google/dependabot/maven/com.github.wvengen-proguard-maven-plugin-2.4.0
Bump proguard-maven-plugin from 2.3.1 to 2.4.0
2021-08-05 06:28:12 -07:00
dependabot[bot] da2bfd7d1c
Bump copy-rename-maven-plugin from 1.0 to 1.0.1
Bumps [copy-rename-maven-plugin](https://github.com/coderplus/copy-rename-maven-plugin) from 1.0 to 1.0.1.
- [Release notes](https://github.com/coderplus/copy-rename-maven-plugin/releases)
- [Commits](https://github.com/coderplus/copy-rename-maven-plugin/commits)

---
updated-dependencies:
- dependency-name: com.coderplus.maven.plugins:copy-rename-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-05 03:03:02 +00:00
dependabot[bot] b7fce3850d
Bump proguard-maven-plugin from 2.3.1 to 2.4.0
Bumps [proguard-maven-plugin](https://github.com/wvengen/proguard-maven-plugin) from 2.3.1 to 2.4.0.
- [Release notes](https://github.com/wvengen/proguard-maven-plugin/releases)
- [Changelog](https://github.com/wvengen/proguard-maven-plugin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/wvengen/proguard-maven-plugin/commits)

---
updated-dependencies:
- dependency-name: com.github.wvengen:proguard-maven-plugin
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-05 03:03:00 +00:00
dependabot[bot] 178b221fa0
Bump maven-resources-plugin from 2.7 to 3.2.0
Bumps [maven-resources-plugin](https://github.com/apache/maven-resources-plugin) from 2.7 to 3.2.0.
- [Release notes](https://github.com/apache/maven-resources-plugin/releases)
- [Commits](https://github.com/apache/maven-resources-plugin/compare/maven-resources-plugin-2.7...maven-resources-plugin-3.2.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-resources-plugin
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-05 03:02:56 +00:00
YOUNG HO CHA d8c5fcf00b Fix indentation of EnumWithObfuscatedTest 2021-08-04 12:30:07 +09:00
YOUNG HO CHA 59a8aedb37 Use SecurityManager to read enum fields 2021-08-04 12:24:55 +09:00
YOUNG HO CHA 20720d6a40 Remove unnecessary catch block 2021-08-04 12:03:28 +09:00
YOUNG HO CHA 6ac9f7d840 Suppress unchecked type cast warning 2021-08-04 12:03:21 +09:00
YOUNG HO CHA 92a98dab02 Removed unused import 2021-08-04 12:03:15 +09:00
YOUNG HO CHA e99a4b1cb7 Move testcases-proguard.conf into gson/src/test/resources 2021-08-04 12:03:10 +09:00
YOUNG HO CHA 1406477d0c Fix post-obfuscate-class task to include obfuscated test classes 2021-08-04 12:03:02 +09:00
YOUNG HO CHA 7988fbfa90 Update proguard plugin to support Java 11 compiler 2021-08-04 12:02:55 +09:00
YOUNG CHA 94f894cf44 Add testcase for obfuscated enum class 2021-08-04 12:02:50 +09:00
YOUNG CHA 68f99f2440 Make EnumTypeAdapter friendly with obfuscation
When enum value was obfuscated by proguard, EnumTypeAdapter raise NoSuchFieldException even if apply SerializedName annotation.
Because EnumTypeAdapter cannot find obfuscated enum constant field with its name.
2021-08-04 12:02:47 +09:00
Éamonn McManus 63e747f7f4
Merge pull request #1712 from rhernandez35/master
Fix fallback behavior of UnsafeReflectionAllocator when AccessibleObject isn't so accessible
2021-08-03 17:27:54 -07:00
Éamonn McManus 425cb25549 Adjust some minor details of #1391.
Use two-space indentation for the new test.
Use standard Google import style.
Supply missing type argument for `TypeVariable`.
2021-08-02 17:33:10 -07:00
Éamonn McManus d65960b001
Merge pull request #1391 from mcumings/issue1390
Fix issue with recursive type variable protections to fix #1390
2021-08-02 16:43:19 -07:00
HiFromAjay 2d1981d39b modify test cases for testing the exceptional behavior of get... methods [use fail(...), use JsonArray methods, remove unused values, formatting, #1909, #1908] 2021-06-14 14:31:14 -06:00
HiFromAjay 55115a5ca2 Test cases for testing the exceptional behavior of get, getAsBoolean, getAsDouble, getAsInt, getAsJsonArray, getAsJsonObject, getAsLong, and getAsString methods of JsonArray class. These test cases, which we wrote according to the specified behavior of each method, that helped us in identifying the documentation bugs in JsonArray and JsonElement classes, which we submitted issues for (Issue #1908). Note that we have adapted these test cases based on similar tests from the JSON-java project (https://github.com/stleary/JSON-java). 2021-06-11 10:04:32 -06:00
Éamonn McManus dadbdbb837 [maven-release-plugin] prepare for next development iteration 2021-05-24 16:22:45 -07:00
Éamonn McManus 4520489c29 [maven-release-plugin] prepare release gson-parent-2.8.7 2021-05-24 16:22:41 -07:00
Éamonn McManus 1e4b84c34f
Merge pull request #1687 from Marcono1234/iso-utils-test-fix
Fix ISO8601UtilsTest failing on systems with UTC+X
2021-05-13 17:19:26 -07:00
Éamonn McManus 829a514aed
Merge pull request #1786 from Marcono1234/marcono1234/JsonStreamParser-doc-fix
Improve incorrect JsonStreamParser doc
2021-05-13 16:45:36 -07:00
dependabot[bot] 83c63d2256
Bump bnd-maven-plugin from 4.0.0 to 5.3.0
Bumps [bnd-maven-plugin](https://github.com/bndtools/bnd) from 4.0.0 to 5.3.0.
- [Release notes](https://github.com/bndtools/bnd/releases)
- [Changelog](https://github.com/bndtools/bnd/blob/master/docs/ADDING_RELEASE_DOCS.md)
- [Commits](https://github.com/bndtools/bnd/commits)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-13 23:31:27 +00:00
tiegen 9cf569698c
Update gson/src/main/java/com/google/gson/GsonBuilder.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
2021-04-26 10:36:30 +08:00
tiegen 527c6cf0d0
Update gson/src/main/java/com/google/gson/GsonBuilder.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
2021-04-26 10:36:02 +08:00
tiegen e6b7da988a
Update gson/src/test/java/com/google/gson/GsonTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
2021-04-25 16:34:26 +08:00
tiegen 8990169194
Update gson/src/test/java/com/google/gson/GsonTest.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
2021-04-25 16:34:18 +08:00
tiegen ccf8484915
Update gson/src/main/java/com/google/gson/GsonBuilder.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
2021-04-25 16:34:04 +08:00
tiegen 897452a3cf
Update gson/src/main/java/com/google/gson/GsonBuilder.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
2021-04-25 16:33:42 +08:00
tiegen 08765cae4c
Update gson/src/main/java/com/google/gson/GsonBuilder.java
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
2021-04-25 16:33:36 +08:00
saddays a0ea108c59 allow deserialize duplicate map key 2021-04-21 14:39:45 +08:00
Marcono1234 b1edb70486 Improve incorrect JsonStreamParser doc 2020-09-19 13:30:50 +02:00
Richard Hernandez b39494dbe6 Fix fallback behavior of UnsafeReflectionAllocator when AccessibleObject isn't so accessible 2020-05-26 20:12:36 -07:00
Marcono1234 a4a235e14a Remove redundant validation method 2020-05-24 23:54:32 +02:00
Marcono1234 4fb215c9df Move SQL types specific tests to separate test class 2020-05-23 23:31:03 +02:00
Marcono1234 380c4ec12c Make dependency on java.sql optional 2020-05-23 23:30:53 +02:00
Marcono1234 361292f1c1 Fix warnings 2020-05-09 17:34:53 +02:00
Marcono1234 541252a9fb Implement DefaultDateTypeAdapter in a type safer way 2020-05-09 17:34:52 +02:00
Marcono1234 9171715a88 Fix ISO8601UtilsTest failing on systems with UTC+X
Previously ISO8601UtilsTest.testDateFormatString() would fail on systems
where the time zone is UTC+X because getTime() returned "2018-06-24" for them.

Additionally the tests which previously changed the system locale and time
zone have been rewritten to create a UTC calendar instead. Setting locale
seems to not be necessary because ISO8601Utils.parse(...) does not do that
either.
2020-05-03 00:35:47 +02:00
Matthew Lee 55acc23d86
Fixing https://github.com/google/gson/issues/1592 (#1623)
adding null parameter check to name(), fixing the issue and being consistent with superclass behavior
2020-03-02 14:57:42 -08:00
Gabriel Basilio Brito fa947212e0
Add isEmpty method to JsonArray class (#1640)
The method will return true if the array is empty and false if it's not
2020-03-02 14:52:37 -08:00
Marcono1234 360cd3e2da
Remove unused files (#1654)
* Remove outdated javadocs folder

* Remove old release notes

* Remove unused Maven assembly plugin file

Plugin usage has been removed in 2016e95
2020-03-02 14:49:47 -08:00
Jiechuan Chen 4d735f1903
Add new testcases (#1638)
* Json Primitive Tests

* Json Tree Writer tests

* Add Tests for ISO8601Utils

* Add Tests for ISO8601Utils
2020-02-17 14:55:19 -08:00
Marcono1234 530cb74470
Fix javadoc doclint HTML warnings (#1653) 2020-02-17 14:46:15 -08:00
Marcono1234 adc4c1949d
Change links from HTTP to HTTPS (#1655) 2020-02-17 14:42:27 -08:00
Brian de Alwis 521fab2dd5 Fix OSGi metadata generation to work on JavaSE < 9 (#1603)
* Explicitly specify `Require-Capability: osgi.ee` to require 1.5+

Specifying disables bnd's auto-generated value which is determined from
the minimum versions of the .class files, including `module-info.class`

* Drop JavaSE-1.5 since that boat sailed a long time ago

* Drop unused org.apache.felix:maven-bundle-plugin plugin
2019-11-04 15:37:46 -08:00
Degubi 9bf25c2eb6 Refactor prefix array & loop logic, use if-s instead (#1505) 2019-10-04 13:45:06 -07:00
Inderjeet Singh d1828736eb [maven-release-plugin] prepare for next development iteration 2019-10-04 11:54:10 -07:00
Inderjeet Singh 29c93895bb [maven-release-plugin] prepare release gson-parent-2.8.6 2019-10-04 11:54:03 -07:00
Paul Kassianik 21fc362a7e Fixed tests for java 11 (#1454) 2019-10-04 11:29:13 -07:00
Degubi 20dca860dd Add docs to module-info.java (#1535) 2019-10-03 15:51:18 -07:00
Degubi 7845c38077 Minor cleanups in deprecations and other warnings (#1522) 2019-10-03 15:49:24 -07:00
David Maplesden 3958b1f78d Prefer writing chars instead of strings of length one (#1576)
This results in a noticeable performance improvement with most writer
implementations (including BufferedWriter).
2019-09-18 10:33:49 -07:00
Degubi 63ee47cb64 Refactor uppercaseFirstLetter, add additional field to test (#1515) 2019-04-26 15:49:22 -07:00
Degubi c5a3f21fba Refactor JsonParser to statics & fix tests 2019-04-15 22:35:10 -04:00
Degubi 477b3f77e1 Refactor primitives class 2019-04-15 11:08:31 -04:00
Degubi 46d0f58d12 Remove unnecessary explicit else statement 2019-04-05 16:20:06 +02:00
Degubi 3ee3c150ed Remove boolean wrappers in JsonElement 2019-03-31 21:28:12 +02:00
Degubi fc63a6af4c Make sql module dependency transitive (#1500) 2019-03-29 09:34:12 -07:00
Manuel Kollus 5370b076e3 Removing 'final' accessor from constructor (#1501) 2019-03-28 09:22:36 -07:00
Degubi 8bf2949c29 Remove object based constructors, remove some internal stuff 2019-03-11 10:53:31 -04:00
Jake Wharton a817604a41 Add test coverage for passing null to JsonPrimitive constuctors 2019-03-11 10:50:22 -04:00