Commit Graph

207 Commits

Author SHA1 Message Date
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
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 73216b2ad7
Add more `Gson` default constants to be used by `GsonBuilder` (#2051) 2022-01-12 07:07:55 -08:00
Marcono1234 615c8835d3
Add `GsonBuilder.disableJdkUnsafe()` (#1904)
* Add GsonBuilder.disableJdkUnsafe()

* Address review feedback
2021-12-30 15:08:18 -08:00
Marcono1234 6ffcdf3029
Fix Javadoc warnings and errors (#2040) 2021-12-26 15:30:21 -08: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 c54caf308c
Deprecate `Gson.excluder()` exposing internal `Excluder` class (#1986) 2021-10-25 11:28:16 -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
Marcono1234 380c4ec12c Make dependency on java.sql optional 2020-05-23 23:30:53 +02:00
Manuel Kollus 5370b076e3 Removing 'final' accessor from constructor (#1501) 2019-03-28 09:22:36 -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
Márton Braun 4d942db168 Update Gson.java documentation to explicitly state behavior for empty strings (#1464) 2019-02-17 00:32:43 -08:00
Piet van Dongen 5bbc768fa6 Fix JPMS module setup (fixes #1315) (#1402)
* Fix JPMS module setup (fixes #1315)

* Re-added cause to AssertionErrors
2018-10-18 08:49:08 -07:00
inder123 d84e26d80c
Issue 1242: Printing Gson version when throwing AssertionError and IllegalArgumentException (#1321)
On some versions of Android (probably on some variants of the popular Samsung S4 phone), an older version of Gson is suspected to be bundled in, and gets picked up from the system classpath.
For those versions, the applications that include the latest Gson fail unexpectedly. This debug print will help confirm this issue.
2018-05-17 09:41:21 -07:00
Warren Smith 08bbb226f1 Add newBuilder() API (#1142)
* Add Gson.newBuilder API.

* Remove redundant test.

* Address Codacy comments.

* Reduce visibility of GsonBuilder constructor.
2017-09-20 18:53:10 -07:00
Nels Beckman ddcd6aea7d Update fromJson Javadoc. (#1151)
For the string-based fromJson() method, mention that the result will be null if the given string is empty.
2017-09-18 00:08:22 -07:00
Mohammad Yasir 92b52d25d8 Performance fix to avoid reflection-based initialization of null key surrogate 2017-04-12 16:11:20 -04:00
Yutaro Iino 9e5e4ac630 Add missing comma in toString() 2016-12-21 00:10:42 +09:00
Inderjeet Singh 1f859ec769 addressed code review comments. 2016-06-14 16:34:34 -07:00
jwilson 2df65502ed Don't use ThreadLocals for @JsonAdapter factories and getDelegateAdapter(). 2016-06-02 00:33:09 -04:00
Inderjeet Singh 45511fdd15 Added support for JsonSerializer/JsonDeserializer for JsonAdapter annotation.
JsonAdapter is cached per the type of the JsonAdapter class.
Added a test to ensure JsonAdapter works on fields of parameterized types
Keep track of registered JsonAdapters and JsonAdapterFactorys in ThreadLocal.
2016-06-02 00:08:25 -04:00
Baschdl c414b368e1 Corrected documentation, copy&paste error 2016-05-12 14:47:03 +02:00
Ryan Harter a851569ab9 Adds getters for config fields.
This adds simple getters for certain config fields that would be helpful in custom
TypeAdapters to deal with situations like this:
https://github.com/rharter/auto-value-gson/issues/18
2016-04-26 15:30:01 -04:00
gavlyukovskiy 966de9e60d fixed throwing RuntimeException instead of JsonIOException 2016-04-15 21:00:59 +03:00
Scott Brown 9c4f352320 minor javadoc fix ... @code block not treated as html 2016-04-08 19:34:05 -06:00
Inderjeet Singh 34d7521d95 moved the JsonSerializationContext/JsonDeserializationContext fields to where they are used.
Also moved TreeTypeAdapter to internal.bind package for potential use in JsonAdapterAnnotationFactory.
2016-03-28 14:46:02 -07:00
qwwdfsad 31dcfa3ad6 More appropriate usage of null key surrogate in Gson#getAdapter for backward compatibility 2016-03-05 02:08:26 +03:00
qwwdfsad c5611847a3 Gson synchronized map replaced with concurrent hash map 2016-03-05 00:28:25 +03:00
Dongjoon Hyun aa209fa255 Fix some typos in gson comments. 2016-02-15 14:11:23 -08:00
Jake Wharton 3360c93a76 Add setting for leniency on Gson instance.
Add a JsonReader factory (for parity with the JsonWriter one) which provides a configured instance using the Gson settings.
2016-01-18 12:08:11 -05:00
Jake Wharton 7a1c94f986 Remove synthetic accessors from being generated. 2015-12-27 01:39:19 -05:00
Inderjeet Singh 47cc34548d added currency class 2015-11-06 15:41:15 -08:00
Inderjeet Singh 11b26b5256 Added support for AtomicLongArray.
Also added tests to ensure LongSerializationPolicy is honored.
2015-11-05 14:15:46 -08:00
Inderjeet Singh caef762530 added factory fields for consistency 2015-11-05 14:03:51 -08:00
Inderjeet Singh cc54e4dbdd made methods static 2015-11-05 10:46:54 -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
Jake Wharton e81f3eba27 Expose newJsonWriter wrapper instead of just options.
This is more future proof to ensure that consumers holding on to TypeAdapters for efficiency can always encode JSON in the same way as if the Gson instance was used directly.
2015-09-26 19:19:38 -04:00
Jake Wharton 31f80d8659 Merge pull request #700 from google/jwilson_0907_serializenulls_accessor
Expose serializeNulls with an accessor.
2015-09-07 22:44:05 -04:00
jwilson ff2c8f8e8b Expose serializeNulls with an accessor.
Useful for frameworks that build on Gson.
2015-09-07 22:31:43 -04:00
Dorvaryn 618343fd1b Clarify the fact that the behaviour of getDelegateAdapter depends on registration order. 2015-09-03 18:15:24 +01:00
Inderjeet Singh 0c4ae01836 Updated Gson Javadoc to indicate thread-safety. 2015-08-10 19:34:07 +05:30
inder123 2ee680a645 Revert "Add a JSR-305 @ThreadSafe annotation to the Gson class" 2015-08-10 19:31:18 +05:30
Stefan Ferstl 82edd57205 Add a JSR-305 @ThreadSafe annotation to the Gson class
- Add an optional dependency to com.google.code.findbugs:jsr305.
  The optional scope is used in order to avoid introducing a new
  transitive dependency to the jsr305 library. This is fine because the 
  @ThreadSafe annotation has only a documentary purpose and it is not
  retained at runtime.
- Annotate the Gson class as @ThreadSafe

Fixes Issue #613
2015-07-13 18:34:38 +02:00
Inderjeet Singh 8d5a41329e added tests for Throwable. Revised ReflectiveTypeAdapterFactory to ignore self-referencing fields. 2014-11-16 22:55:18 +00: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
Inderjeet Singh f2591b6664 adjusted factory finding code to take into account non-present factories 2014-11-10 23:15:31 +00:00
Jake Wharton 7f8f490fdc Re-order factories to allow @JsonAdapter on enums which are user-defined types. 2014-11-04 00:59:42 +00:00
Jesse Wilson 125e6d9d3d Change field annotations to take precedence over registered type adapters. 2014-08-02 18:22:43 +00:00