Commit Graph

81 Commits

Author SHA1 Message Date
Johannes Frohnmeyer 89ae8b48c2
Merge remote-tracking branch 'origin/master'
ci/woodpecker/push/woodpecker Pipeline was successful Details
# Conflicts:
#	extras/pom.xml
#	extras/src/main/java/com/google/gson/graph/GraphAdapterBuilder.java
#	extras/src/main/java/com/google/gson/interceptors/InterceptorFactory.java
#	extras/src/test/java/com/google/gson/typeadapters/PostConstructAdapterFactoryTest.java
#	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/util/ISO8601Utils.java
#	gson/src/main/java/module-info.java
#	gson/src/test/java/com/google/gson/GsonTest.java
#	gson/src/test/java/com/google/gson/functional/ArrayTest.java
#	gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java
#	gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java
#	gson/src/test/java/com/google/gson/functional/EnumWithObfuscatedTest.java
#	gson/src/test/java/com/google/gson/functional/InternationalizationTest.java
#	gson/src/test/java/com/google/gson/functional/Java17RecordTest.java
#	gson/src/test/java/com/google/gson/functional/JavaUtilConcurrentAtomicTest.java
#	gson/src/test/java/com/google/gson/functional/JavaUtilTest.java
#	gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnClassesTest.java
#	gson/src/test/java/com/google/gson/functional/JsonAdapterAnnotationOnFieldsTest.java
#	gson/src/test/java/com/google/gson/functional/JsonParserTest.java
#	gson/src/test/java/com/google/gson/functional/MapTest.java
#	gson/src/test/java/com/google/gson/functional/PrimitiveTest.java
#	gson/src/test/java/com/google/gson/functional/ReflectionAccessTest.java
#	gson/src/test/java/com/google/gson/functional/StreamingTypeAdaptersTest.java
#	gson/src/test/java/com/google/gson/functional/TypeAdapterPrecedenceTest.java
#	gson/src/test/java/com/google/gson/internal/bind/Java17ReflectiveTypeAdapterFactoryTest.java
#	gson/src/test/java/com/google/gson/internal/bind/JsonTreeReaderTest.java
#	gson/src/test/java/com/google/gson/internal/bind/JsonTreeWriterTest.java
#	gson/src/test/java/com/google/gson/internal/reflect/Java17ReflectionHelperTest.java
#	gson/src/test/java/com/google/gson/regression/JsonAdapterNullSafeTest.java
#	gson/src/test/java/com/google/gson/stream/JsonReaderPathTest.java
#	gson/src/test/java/com/google/gson/stream/JsonReaderTest.java
#	metrics/pom.xml
#	metrics/src/main/java/com/google/gson/metrics/NonUploadingCaliperRunner.java
#	metrics/src/main/java/com/google/gson/metrics/ParseBenchmark.java
#	pom.xml
#	proto/pom.xml
2023-02-23 14:21:42 +01:00
Maicol 2658aca66a
Fix error prone warnings (#2316)
* 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()`
2023-02-15 05:18:43 -08:00
Johannes Frohnmeyer 51157e81e5
Move some stuff around
ci/woodpecker/push/woodpecker Pipeline failed Details
2023-01-21 14:27:59 +01: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 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 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
Marcono1234 4dda4ec5ba
Use diamond operator when creating generic instances (#2104) 2022-04-17 15:27:21 -07: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 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 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 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
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
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
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 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
Marcono1234 380c4ec12c Make dependency on java.sql optional 2020-05-23 23:30:53 +02:00
Anirudh Ramanan 3bf1967c0a Optimised the create() call for Excluder TypeAdapterFactory (#1199)
* optimized the create() method, excludeClass used to get called two times, changed it to one

* fixed the create() method, and added support to disableAnonymousAndLocalClassSerialization

* peek only once

* enable anonymous and local class serialization

* bugfix

* removed the method, will raise it as a separate PR
2017-12-28 06:03:45 +05:30
Anirudh Ramanan 9e44d60b83 Eliminating code overhead
* calculating size of the list once in case of loops, avoided creation of string builder object if the length type argument is 0
* replaced null check boilerplate code with nullSafe()
2017-03-01 11:13:56 -05:00
Egor Neliuba 44cad04a63 Allow deserialization of a Number represented as a String (#964) 2016-11-25 23:40:14 -08:00
Inderjeet Singh 61f83d6309 Replaced a JDK 1.7 specific method with its JDK 1.6 equivalent. 2016-05-17 01:03:00 -07:00
Jake Wharton 59edfc1caf Add boxed boolean value() overload.
When calling value() with a Boolean overload resolution would choose value(boolean) which would throw an NPE on null. The other boxed types are all numbers which would resolve to value(Number) and behave correctly.
2016-04-22 19:52:38 -04:00
inder123 e48c780389 Merge pull request #733 from google/java_util_additional_classes
Supported Currency and added additional tests for Vector, Stack and Properties.
2015-11-17 17:57:59 -08:00
Inderjeet Singh 05b17f9271 Adding details in the throw exception on a missing field. 2015-11-16 09:12:23 -08:00
Inderjeet Singh 47cc34548d added currency class 2015-11-06 15:41:15 -08:00
Inderjeet Singh caef762530 added factory fields for consistency 2015-11-05 14:03:51 -08:00
Inderjeet Singh 7821b73202 Added support for AtomicInteger, AtomicBoolean, AtomicLong and AtomicIntegerArray. 2015-11-05 10:45:23 -08:00
Inderjeet Singh e5b3f6368d updated minimum JDK version to 1.6.
Added Overrides for methods implementing an interface.
2015-11-04 18:52:20 -08:00
inder123 fe101c10bc Merge pull request #719 from google/jwilson_1021_runtime_type_mismatch
Fix type hierarchy adapters to do a runtime check.
2015-10-22 09:29:01 -07:00
jwilson 7d1973e6c5 Fix type hierarchy adapters to do a runtime check.
Otherwise if we have a type hierarchy adapter for Vehicle, and we
attempt to decode a JSON string as a Car, we get the right exception
if the JSON string is actually decoded as a Truck.
2015-10-21 11:42:30 -04:00
Inderjeet Singh 109915d93a Implemented support for multiple values for SerializedName annotation. 2015-10-03 02:01:30 -07:00
Vladislav Bauer eb79ec73f0 Add unit tests for constructors from util classes 2015-08-15 05:29:46 +06:00
Inderjeet Singh b6a625fb6c fixed issue 469 by adding a TypeAdapterFactory for throwables that ignores cause if it is self-referencing 2014-11-16 22:25:23 +00:00
Jesse Wilson 6a69c603c0 Permit serialization of "Class" fields, but only if they're null. 2013-02-04 15:52:51 +00:00
Joel Leitch 6d90f0d894 Make JsonElement TypeAdapterFactory a type hierarchy factory. 2012-12-20 07:57:17 +00:00
Jesse Wilson dd86d63436 Use inner classes for BigDecimal and BigInteger type adapters 2012-02-11 20:14:23 +00:00
Jesse Wilson d7fbac0384 Rename TypeAdapter.Factory to TypeAdapterFactory. 2011-12-23 18:27:13 +00:00
Inderjeet Singh 82f18a257f Implemented code review comments from r1090 2011-12-23 15:52:10 +00:00
Inderjeet Singh bd937fe7b5 A type adapter for Class that throws an UnsupportedOperationException. 2011-12-22 22:31:43 +00:00
Inderjeet Singh b5ae3c945a Incorporated code review from r949 2011-12-16 19:10:54 +00:00
Jesse Wilson a3ca4e1312 Admit to a mistake in InetAddress' type adapter 2011-12-16 19:05:10 +00:00
Jesse Wilson c01fc5c935 Fix tests broken by r1078. 2011-12-16 14:12:34 +00:00
Jesse Wilson 214234e202 Support @SerializedName on annotations.
Fixes issue 347.
2011-12-16 05:32:50 +00:00
Jesse Wilson f602bce9f5 Nice documentation for TypeAdapter. 2011-12-03 19:46:25 +00:00
Jesse Wilson 26ab404599 Cleanup names for TypeAdapters. 2011-12-02 22:57:30 +00:00
Jesse Wilson f777a192ee Remove dead code and fold contents of single-member helper classes into their clients. 2011-11-20 21:02:26 +00:00
Jesse Wilson 7e760143fd Smash together MiniGson and Gson. This changes Gson to be the MiniGson rather than delegating to the MiniGson. It means that the MiniGson objects passed into streaming type adapters are now fully-capable 'Gson' objects.
The most notable impact of this change is that it adds several new public APIs:
 - The TypeAdapter abstract class
 - The TypeAdapter.Factory interface
 - Four new methods on GsonBuilder to register streaming TypeAdapters (via Factory, via Class, via TypeToken, and as a type hierarchy)
 - Three new methods on Gson to lookup streaming TypeAdapters (by type, by class, and to get the next type adapter) 

Still outstanding:
 - Write beautiful prose to document the new APIs above
 - Change GsonBuilder's precedence so that both old and new-style type adapters are registered in one lot
2011-11-20 15:23:08 +00:00
Jesse Wilson 0340e01f98 Support booleans as strings in stream binding. Remove support for interpreting "1" as true.
Interpreting '1' as true was not backwards compatible.
2011-10-23 21:41:30 +00:00