Commit Graph

21 Commits

Author SHA1 Message Date
Éamonn McManus 18bdb6db2a
Fix a couple of types in tests. (#2317)
These show up with recent Error Prone analyses for Truth. Because the
tests use the overload of `Gson.fromJson` that takes a `Type` argument,
rather than the one with a `TypeToken`, the type mismatches were not
detected by the compiler.
2023-02-15 05:53:29 -08:00
Maicol 49b00d1a86
Port all Junit assert to Truth asserts (#2304)
* Port Junit assert to Truth in `com.google.gson.stream`

* Port Junit assert to Truth in `com.google.gson.regression`

* Port Junit assert to Truth in `om.google.gson.reflect`

* Port Junit assert to Truth in `com.google.gson.metrics`

* Port Junit assert to Truth in `com.google.gson.internal`

* Port Junit assert to Truth in `com.google.gson.internal.sql`

* Port Junit assert to Truth in `com.google.gson.internal.reflect`

* Port Junit assert to Truth in `com.google.gson.internal.bind`

* Port Junit assert to Truth in `com.google.gson.internal.bind.util`

* Port Junit assert to Truth in `com.google.gson.functional`

* Replaces `List.of` with `Arrays.asList` to grant legacy

* Simplify `==` asserts

* Simplify `.contain()` asserts + Minor fixes

* Simplify asserts
2023-01-31 11:20:54 -08: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
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 4dda4ec5ba
Use diamond operator when creating generic instances (#2104) 2022-04-17 15:27:21 -07:00
Degubi 7845c38077 Minor cleanups in deprecations and other warnings (#1522) 2019-10-03 15:49:24 -07:00
Lorenz Nickel b75e1bbc79 Code cleanup (Removed spaces) (#1474)
* Removed double spaces in comments

* Unified comments

* Removed space

* Removed spaces in code
2019-03-03 11:18:06 -08:00
Jesse Wilson e9521471aa Fix typo: Paramterized was spelled wong. 2011-11-20 20:31:10 +00:00
Jesse Wilson de727d8c48 Delete dead code found by coverage 2011-10-01 02:04:48 +00:00
Inderjeet Singh 824635158c Parsing numbers lazily as a performance enhancement.
This avoids needing to parse number if the equivalent object field doesn't exist.
It also avoids the performance penalty of trying to parse it eagerly as a big decimal, float etc.
2011-04-28 21:57:29 +00:00
Joel Leitch 8297437610 Reverting r499. 2009-09-23 19:25:50 +00:00
Joel Leitch c6f762f36b Fix Warnings 2009-09-23 19:09:01 +00:00
Inderjeet Singh 3b0f8f4340 Removed all the JDK warnings about unused fields in test classes or unused constructors for use by Gson or instanceof calls on parameterized types. 2009-09-23 17:45:16 +00:00
Joel Leitch 18b301dfeb - Serializing of Object arrays.
- Fixed incorrect warning
2009-09-22 19:04:27 +00:00
Inderjeet Singh 82771f006c removed Java 1.5 warnings 2009-08-31 17:51:47 +00:00
Joel Leitch c9cb05fc72 Do not leak out a ClassCastException to our clients. 2009-03-27 19:43:33 +00:00
Inderjeet Singh 3d1f7251c1 Added tests to reproduce issue 103. The tests pass at the moment, so we need more information in the bugreport. 2009-03-12 01:04:30 +00:00
Joel Leitch 458f2baa2f Added special serialization of "Long". Now the client has the ability to output a long field as a JSON "String". This is useful for JavaScript clients that need to handle long values.
As well, this change does a major clean up of the custom type adapter handling and ParameterizedTypeMap creation.
2008-12-28 03:23:36 +00:00
Joel Leitch 0d8150fe52 Major restructuring of Primitve type serialization and deserializtion. From the end-user's point of view there should be no difference other than the user can now override the default serialization/deserialization their own custom type adapter (not sure if there is a real use-case out there for this).
This restructuring greatly cleans up the code and reduces some complexity; however, there is more that can be done to clean this up (i.e. get rid of "InstanceCreators" for primitive Type Adapters).
2008-11-15 02:26:57 +00:00
Inderjeet Singh 9245bebdba For the Collection and Map types, using ObjectConstructor to create instance instead of hard-coding a specific type.
This helps is handling cases where the user is using their own subclass of Collection or Map.

Updated ParameterizedTypeHandlerMap to return the handler corresponding to Map and Collection for subclasses if user has not specified a specific handler.

Fixed the logic in JsonTreeNavigator to not output a comma if the first field of an object was null.
2008-11-14 02:11:46 +00:00
Inderjeet Singh 57d1f32de5 moved gson as a project under trunk 2008-09-01 03:13:32 +00:00