Commit Graph

867 Commits

Author SHA1 Message Date
inder123
1f803bd37d Merge pull request #761 from google/jw/nuke-synthetics
Remove synthetic accessors from being generated.
2015-12-27 14:08:23 -05:00
Jake Wharton
7a1c94f986 Remove synthetic accessors from being generated. 2015-12-27 01:39:19 -05:00
Gorik
d86dfdec7c Removed unused code in ISO8601Utils 2015-11-23 01:21:41 -05:00
Gorik
bcd52a1fdc Added ISO8601 complete support for date deserialization 2015-11-23 01:11:41 -05: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
c935f89b23 Added the cause to Assertions 2015-11-16 09:16:23 -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
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
fef43b2aaa Added support to serialize/deserialize ConcurrentMap and ConcurrentNavigableMap. 2015-11-04 21:25:15 -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
Roman Mazur
3b1671dde9 Fix javadoc of SerializedName
In #699 the approach was changed but docs were left for the first implementation.
2015-10-04 19:56:02 +03:00
Inderjeet Singh
109915d93a Implemented support for multiple values for SerializedName annotation. 2015-10-03 02:01:30 -07:00
Jesse Wilson
3361030766 Merge pull request #705 from google/627
Implemented equals and hashcode for LazilyParsedNumber to fix
2015-09-27 17:25:04 -04:00
Inderjeet Singh
96b2ada79a incorporated code review feedback: optimized LazilyParsedNumber.equals/hashcode() by utilizing the fact that value is never passed as null. 2015-09-27 13:58:01 -07:00
dushyant
2ecce94494 typo 2015-09-27 16:01:27 +05:30
Inderjeet Singh
1e9004403c Fixed javadoc for JsonWriter as reported in
https://github.com/google/gson/issues/623
2015-09-26 18:10:00 -07:00
Inderjeet Singh
3aec173243 small reformatting 2015-09-26 18:02:12 -07:00
Inderjeet Singh
3daf585931 Implemented equals and hashcode for LazilyParsedNumber to fix
https://github.com/google/gson/issues/627
2015-09-26 17:58:13 -07: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
Jesse Wilson
87717662f7 Merge pull request #689 from vbauer/util-classes
Add unit tests for constructors from util classes
2015-08-14 20:42:31 -04:00
Vladislav Bauer
eb79ec73f0 Add unit tests for constructors from util classes 2015-08-15 05:29:46 +06:00
Michael Evans
64d74db8ae Add METHOD target for use with AutoValue's abstract property methods 2015-08-14 14:08:56 -04: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
inder123
0a93efada5 Merge pull request #652 from schlan/fix_turkish_locale_issues
Fix issues if runing in an environment with a Turkish locale
2015-08-08 09:10:48 -07:00
Dillon Dixon
d8c12a727f Fixed accidental duplication of null elements 2015-07-23 21:18:01 -07:00
Dillon Dixon
6960ebc776 Updated JsonArray to support adding primitives directly via an overloaded "add(...)" method rather than having to always do "add(new JsonPrimitive(...))" 2015-07-23 20:44:04 -07:00
Adam Tanner
f7abd59a3b JsonWriter#jsonValue writes raw JSON values.
Add a jsonValue(String value) method that takes a raw JSON string that
can be used to write the string directly to the underlying writer
without modification.

The intended use case for this is when building JSON that contains a
pre-serialized JSON string as a value in an object or array.
2015-07-20 10:56:56 -07:00
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
Jake Wharton
032847976c There is no I/O writing to a StringWriter. 2015-06-17 22:01:17 -04:00
Sebastian Chlan
6e57df7e96 FieldNamingPolicy: Use Locale.ENGLISH to be locale insensitive 2015-06-09 15:25:16 +01: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
1de2ace065 removed eclipse warnings. updated maven plugins to the latest versions 2014-11-16 20:45:01 +00:00
Jesse Wilson
d6c8c1e3cf Fix bugs in getPath() with arrays of objects and arrays of arrays 2014-11-11 01:59:48 +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
Jake Wharton
c5dc3b791b Correct JsonElement javadoc exception references. 2014-08-09 06:14:12 +00:00
Jake Wharton
f4185289f6 Correct TypeAdapterFactory reference in its Javadoc. 2014-08-09 05:35:33 +00:00
Jake Wharton
f1f838cf20 Favor post-Gingerbread instantiation mechanism.
pre-Gingerbread is now a small subset of the Android OS distribution and is constantly shrinking toward zero.
2014-08-09 05:32:50 +00:00
Jesse Wilson
6a3e83a741 Javadoc for TypeAdapterFactory in @JsonAdapter. 2014-08-05 15:00:15 +00:00
Jake Wharton
117d8ea68f Add TypeAdapterFactory support to @JsonAdapter. 2014-08-04 16:58:41 +00:00
Jesse Wilson
125e6d9d3d Change field annotations to take precedence over registered type adapters. 2014-08-02 18:22:43 +00:00
Inderjeet Singh
f9a302e22a incorporated code review feedback. Added a test to ensure JsonAdapter validation doesn't carry side-effects to other fields 2014-08-01 02:16:42 +00:00
Jesse Wilson
fbc7e69c81 Implement JsonPath in JsonReader. 2014-07-31 05:17:54 +00:00
Inderjeet Singh
80bbf4a85a revised JsonArray.set() method to return the JsonElement. (thanks Buchholz Bastian for catching that!) 2014-07-04 17:31:43 +00:00
Inderjeet Singh
b9578a4d7e renamed JsonArray.has() to JsonArray.contains() 2014-07-04 02:03:34 +00:00
Inderjeet Singh
94e21eca21 renamed JsonArray.contains() to has() to be consistent with JsonObject.has() 2014-07-03 17:31:07 +00:00
Inderjeet Singh
06282a4d13 Fixed issue code.google.com/p/google-gson/issues/detail?id=353 by adding set method in JsonArray 2014-07-02 18:30:17 +00:00
Inderjeet Singh
9bbdcac5a8 Fixed issue code.google.com/p/google-gson/issues/detail?id=353 by adding remove and contains methods in JsonArray 2014-07-02 18:21:36 +00:00
Jesse Wilson
c6752fc47a Fix inverted docs in ExclusionStrategy. 2014-06-04 04:30:19 +00:00
Jesse Wilson
a411a766f7 Leitch --> Wilson ! 2014-05-23 05:43:39 +00:00
Inderjeet Singh
14ba59fa88 code review fixes. Moved getFirstArgument() method from $Gson$Types to GsonTypesTest. 2014-05-19 17:34:25 +00:00
Inderjeet Singh
b373c20136 Fixed issue 552 by documenting when fromJson returns null. 2014-03-29 23:28:52 +00:00
Inderjeet Singh
c53e255105 Fixed typo as mentioned in issue 565 2014-03-26 18:07:59 +00:00
Inderjeet Singh
edf66083e6 renamed @Adapt to @JsonAdapter 2014-03-26 17:59:54 +00:00
Inderjeet Singh
7f6a096030 renamed JsonAdapter annotation to Adapt annotation. 2014-03-09 23:08:54 +00:00
Inderjeet Singh
6e8d3cd65e Created threadsafe implementation of JsonAdapter invocation. Also fixed a bug where runtime generated typeadapters were being carried over from a toJson/fromJson call to the next. 2014-03-09 23:00:53 +00:00
Inderjeet Singh
e280ffd7e2 Fixed broken test to ensure that a field JsonAdapter annotation supersedes the class JsonAdapter annotation.
Added a map in Gson to keep track of TypeAdapters which are generated by Gson.
2014-03-09 08:36:24 +00:00
Inderjeet Singh
0922af5be6 removed invalid imports 2014-03-09 08:23:05 +00:00
Inderjeet Singh
67af0dd8f8 Added javadoc comment in JsonAdapter explaining the usage for fields.
Added a (broken) test the ensure a field annotation for JsonAdapter supersedes a class annotation.
2014-03-09 08:21:06 +00:00
Inderjeet Singh
f88eee094c removed some eclipse warnings 2014-03-09 07:33:08 +00:00
Inderjeet Singh
b9998e511f deleted support for the magic GSON_TYPE_ADAPTER field 2014-03-09 07:30:37 +00:00
Inderjeet Singh
bf549f0589 Added support for JsonAdapter annotation on fields 2014-03-09 07:28:04 +00:00
Inderjeet Singh
67d512ee7d Created a JsonAdapter annotation that can be applied to classes to indicate their TypeAdapter. 2014-03-08 22:37:19 +00:00
Inderjeet Singh
7c97ac2944 Updated Gson version to 2.3-SNAPSHOT since this is a new feature.
Added support for a magic field GSON_TYPE_ADAPTER in a class. This adapter is automatically invoked if present.
The field must be present in the class (not in any super-type), and must be strongly typed as TypeAdapter<T>.
2014-03-08 20:08:13 +00:00
Inderjeet Singh
b2a9d872db deleted redundant and invalid precondition. 2014-03-08 19:33:24 +00:00
Inderjeet Singh
c3d0f200b3 Fixed a bug where an inner static class was incorrectly marked as non-static while creating parameterized types. 2014-03-08 19:12:24 +00:00
Jesse Wilson
1840466704 Fix a nasty bug where elements in LinkedHashTreeMap could be dropped.
The underlying problem is that the doubleCapacity function would drop the parent links when all nodes ended up on the same side in a doubling. This was caused by the fact that the AvlIterator was destructive on parent nodes, and we weren't putting them back together with the AvlBuilder. This removes an incorrect optimization and fixes the problem.

Also move LinkedHashTreeMap back into main from test.
2013-05-14 21:43:20 +00:00
Joel Leitch
8834343861 Moving broken class to "test" package for now and disabling broken test. 2013-05-13 21:01:33 +00:00
Joel Leitch
2d5cab1b7b Fix hashing in LinkedHashTreeMap, but it still does not work :( 2013-05-13 20:40:07 +00:00
Joel Leitch
3f4bc4cd10 Remove unused import 2013-05-13 20:38:35 +00:00
Joel Leitch
e4508227c5 Added test to use BigDecimal to parse number when requesting it as a long. 2013-05-13 20:37:33 +00:00
Joel Leitch
f29d5bc37b Create a LinkedTreeMap based on the LinkedHashTreeMap; however, removed all the hashing from it as resorted to a single tree. The insertion order is still preserved. 2013-05-03 16:11:16 +00:00
Inderjeet Singh
6347e9b9c6 ensuring that LinkedHashTreeMap.contains() returns false when non-Comparable() keys are passed to it 2013-04-12 21:10:21 +00:00
Inderjeet Singh
6f0a6a4662 made inner classes static and final 2013-04-12 20:20:53 +00:00
Inderjeet Singh
ae034b5ca2 eliminated eclipse warnings by adding a default label to switch. 2013-04-12 20:14:50 +00:00
Inderjeet Singh
26016ca66e removed eclipse warnings, unused fields. Made inner classes static where possible. 2013-04-12 20:09:08 +00:00
Joel Leitch
70f9280cb6 Remove usage of StringPool as it appears to slow things down and avoid Java String intern for the common cases. 2013-04-08 18:36:23 +00:00
Inderjeet Singh
edd6c19670 deleted unused enum and reordered imports 2013-04-04 21:40:05 +00:00
Joel Leitch
af6aa5f782 Use the LinkedHashTreeMap instead of LinkedTreeMap and delete the LinkedTreeMap version. 2013-04-04 21:31:23 +00:00
Inderjeet Singh
7d53113ebc fixed https://code.google.com/p/google-gson/issues/detail?id=509 by adding construction for EnumSet 2013-04-04 21:15:50 +00:00
Jesse Wilson
63142f621c Use the right method name in error messages.
Fixes issue 498.
2013-02-04 16:05:00 +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
edf326e756 Tag member fields as transient since a LinkedHashMap is used for serialization. 2013-01-15 20:04:26 +00:00
Joel Leitch
6dc6b4be92 Fix object leak from ThreadLocal. 2013-01-14 22:05:28 +00:00
Joel Leitch
84201c015f Do not peek during a "skipValue" if a value has already been peeked. 2013-01-14 18:38:46 +00:00
Joel Leitch
3f2efac95e Stop blowing up on a null key, but rather return that the element is not found. 2013-01-09 23:37:38 +00:00
Joel Leitch
b0531e1649 Ensure "excluder" is added prior to user defined type adapters/factories.
- Added test expose bad behaviour.
2012-12-20 19:41:33 +00:00
Joel Leitch
6d90f0d894 Make JsonElement TypeAdapterFactory a type hierarchy factory. 2012-12-20 07:57:17 +00:00
Joel Leitch
040bae34d7 Allowing instance creators to be registered with the raw type only (without specifying type parameters). 2012-10-24 20:40:44 +00:00
Jesse Wilson
af4879dbb7 Move interceptors from 'alpha' to 'extras'.
This makes the feature less risky to use! It now uses our
TypeAdapterFactory infrastructure rather than relying on
parallel infrastructure.
2012-10-23 17:36:30 +00:00
Jesse Wilson
1e18dce002 Don't subclass ThreadLocal.
This attempts to address issue 402, wherein subclassing ThreadLocal is pinning a reference to a class, which transitively pins the entire application in containers like Tomcat.
2012-10-23 02:41:34 +00:00
Jesse Wilson
22c835f2bc Fix compile warnings 2012-10-23 02:40:14 +00:00
Inderjeet Singh
fd4fbe4132 Added support for collections, maps, and arbitrary depth of type adapters for Intercept annotation.
Added more tests for the features.
2012-10-18 02:37:43 +00:00
Inderjeet Singh
c25278b4d6 Created an alpha package that holds experimental feature.
Added support for JsonPostDeserializer that allows you to invoke postDeserialize methods on an Gson deserialized object.
2012-10-11 03:20:36 +00:00
Joel Leitch
14f16e2d0c Adding Red-Black Tree implementation and tying it into the Gson bindings. 2012-10-11 03:15:49 +00:00
Jesse Wilson
2fef83799d Optimizations and bug fixes for LinkedHashTreeMap.
The most interesting optimization is to replace ArrayDeque with a manual linked list that reuses the nodes 'parent' field. These optimizations save about 20%.
2012-09-17 03:30:20 +00:00
Jesse Wilson
aceadaecf1 Add a hashing layer to LinkedTreeMap. Instead of having 1 root node, the class now has several root nodes, one for each hash bucket in a hash table.
Compared to LinkedTreeMap, this is slower for small (size=5) maps: 124% slower to get() and 33% slower to create and populate. It's a win for large (size=500) maps: 46% faster to get() but 8% slower to create and populate. And it's a big win for very large (size=50,000) maps: 81% faster to get() and 46% faster to create and populate.

http://microbenchmarks.appspot.com/run/limpbizkit@gmail.com/com.google.common.collect.MapBenchmark

I'm going to follow this up with some simple optimizations: caching local fields and simplifying access. That should narrow the performance gap.
2012-09-17 00:19:44 +00:00
Jesse Wilson
a0493b9732 New code that can split an AVL tree into two AVL trees.
This is in preparation for a new feature where LinkedTreeMap will have multiple roots, each in its own hash bucket.
2012-09-15 06:13:33 +00:00
Jesse Wilson
01bd0d92e2 Tests for LinkedTreeMap with incompatible keys. 2012-09-12 05:06:48 +00:00
Jesse Wilson
a6ab854302 Fix a bug where we were unlinking nodes that shouldn't have been unlinked.
Found by Guava's awesome collections test suite!
2012-09-12 04:41:58 +00:00
Jesse Wilson
93e38901df Draft of LinkedTreeMap. Its ordered like a LinkedHashMap but it doesn't do any hashing for DoS resistance.
Not yet adopted in our code.

Known critical bugs:
 - throws ClassCastException when get() is called with a non-comparable key
 - throws NullPointerException on get(null)
2012-09-10 20:04:38 +00:00
Jesse Wilson
084047d80b Reintroduce string pooling in JsonReader.
This makes Hotspot slower. From my before/after measurements using ParseBenchmark, times in microseconds:
  TWEETS: 350 -> 370 (+6%)
  READER_SHORT: 77 -> 76 (-1%)
  READER_LONG: 870 -> 940 (+8%)
  
But it makes Dalvik faster by a greater margin. These before/after measurements use times in milliseconds:
  TWEETS: 25 -> 20 (-20%)
  READER_SHORT: 5.6 -> 4.7 (-16%)
  READER_LONG: 52 -> 47 (-10%)
 
 It's a net win because we're saving a greater fraction of time, and because we're helping the platform that needs the most help. We're paying microseconds on Hotspot to gain milliseconds on Dalvik.
2012-09-10 16:13:33 +00:00
Jesse Wilson
411c5c0b50 Follow up on r1197 and make deepCopy package-private. We don't want to use protected because some of the classes are non-final and protected shows up in the Javadocs. 2012-09-03 23:30:27 +00:00
Inderjeet Singh
a973837dd4 made deepCopy protected to eliminate it from the public API for now.
It will be in the subsequent release.
2012-09-03 08:34:37 +00:00
Jesse Wilson
8df7209074 Fix cut & paste issue in JsonToken Javadocs.
Fixes issue 463.
2012-09-02 21:29:30 +00:00
Jesse Wilson
b3b919770b Change number parsing to use one big loop. This changes it to return JsonToken.STRING for very long (>8k digits) numbers. 2012-09-02 20:12:19 +00:00
Jesse Wilson
3920d95fac rename peekedInteger to peekedLong 2012-09-02 17:46:02 +00:00
Jesse Wilson
8daf3aaeb4 Inline position computation. This is uglier but faster. 2012-08-28 03:52:18 +00:00
Jesse Wilson
46b73632b0 Fix a bug where we weren't reading enough characters when a BOM was encountered. 2012-08-28 01:48:25 +00:00
Jesse Wilson
980796005f Use a conventional for loop in nextQuotedValue() to make hotspot's job easier. 2012-08-27 04:42:39 +00:00
Jesse Wilson
bdf2cac6d4 Replace switch with if/else when processing whitespace. If/else is faster! 2012-08-27 04:17:29 +00:00
Jesse Wilson
b0a172944a More number parsing improvements. 2012-08-27 03:17:41 +00:00
Jesse Wilson
448063dde1 Fix a goof in number parsing. 2012-08-27 03:07:20 +00:00
Jesse Wilson
4c2980e6ff Fix a bug in integer parsing. 2012-08-27 02:34:52 +00:00
Jesse Wilson
c7cb503cdb Restore fast skips.
document            api      ns linear runtime
      TWEETS    GSON_STREAM  397568 =========
      TWEETS      GSON_SKIP  300058 =======
READER_SHORT    GSON_STREAM   76632 =
READER_SHORT      GSON_SKIP   57796 =
 READER_LONG    GSON_STREAM  894690 =====================
 READER_LONG      GSON_SKIP  565114 =============
2012-08-27 01:17:50 +00:00
Jesse Wilson
085856c128 Don't leave the JsonReader in an invalid state if nextInt(), nextDouble() or nextLong() fails. We now save a reference to the string before we parse it, and keep that referenced value if parsing fails. 2012-08-26 22:06:57 +00:00
Jesse Wilson
e7bfd0c97d Promote JsonReader2 to be the main JsonReader implementation. 2012-08-26 19:34:46 +00:00
Jesse Wilson
553fa6b742 Prepare to replace JsonReader with JsonReader2 2012-08-26 19:33:49 +00:00
Jesse Wilson
b96d2d9837 Support non-execute prefixes. 2012-08-26 19:31:06 +00:00
Jesse Wilson
97cb326ad2 Delete an old version of the rewritten JsonReader 2012-08-26 04:04:22 +00:00
Jesse Wilson
46b4346505 Get JsonReader2 to the point that it's passing most tests.
Still missing: 
 - non-execute prefixes
 - rolling back 'pos' when a double fails to parse
 - octal prefix failures
2012-08-26 04:02:09 +00:00
Jesse Wilson
c5c65ba626 Add an experimental rewrite of JsonReader.
The motivating difference is that JsonReaderV2 tries to read each character at most once. This means that when it reads literals, it also attempts to decode them to a keyword (true/false/null) or a number.

This change also _doesn't_ read strings until demanded to do so. This should permit streaming access to strings down the road.

This code is not yet complete, nor is has it been properly optimized. And the implementation is also quite a mess! It is a work in progress.
2012-08-25 04:31:56 +00:00
Jesse Wilson
9c4b23b39a JsonObject.deepCopy() for Gson. 2012-08-21 01:19:43 +00:00
Jesse Wilson
1a4f690335 Regretfully enable serialization for StringMap and LazilyParsedNumber.
One of our favorite users (my employer!) is stuck in a sad situation where they need to serialize objects returned from Gson; this is a workable escape hatch.
2012-08-15 14:58:26 +00:00
Jesse Wilson
35c13173b0 Switch on ints rather than enums in JsonReader.
Using enums was triggering this Android bug:
http://code.google.com/p/android/issues/detail?id=36349
2012-08-14 21:32:18 +00:00
Jesse Wilson
f406d3cf89 Don't fall back when we're already in the slow case. 2012-07-10 23:45:20 +00:00
Jesse Wilson
4aaa4bf20c StringMap was suffering because the string's hashCode was not cached. Address this by preferring the regular String.hashCode until hash collision problems start to occur. 2012-07-10 18:46:01 +00:00
Inderjeet Singh
b946a229b6 deleted unused field. 2012-07-03 00:28:55 +00:00
Jesse Wilson
4816941f0d Address code review comments on r1154 2012-07-02 20:32:38 +00:00
Inderjeet Singh
6575cdebca When EOF is encountered prematurely, Streams.parse() (and JsonParser) now throw JsonSyntaxException. 2012-07-02 18:36:54 +00:00
Inderjeet Singh
582b0a0c9c Fixed issue 443 by relying on Streams.parse() to return a JsonNull on empty documents and throw a JsonParseException otherwise. 2012-06-30 18:48:11 +00:00
Jesse Wilson
1c7aee40f3 Implement Flushable. 2012-06-30 02:46:26 +00:00
Jesse Wilson
dc4e43bb23 Permit users to define type adapters for primitive types and strings.
Also expose an API to get the field naming strategy.
2012-06-30 02:37:49 +00:00
Inderjeet Singh
83e5a4937c Renamed Gson.getNextAdapter to getDelegateAdapter.
Deleted testParameterizedMapSubclassDeserialization which we decided to not fix.
Added simple tests for getDelegateAdapter
2012-04-12 18:49:27 +00:00
Jesse Wilson
3df2db1f16 Don't permit a type adapter for String to be registered. 2012-04-12 18:27:48 +00:00
Jesse Wilson
6d351fea07 Fix a documentation typo.
Fixes bug 423.
2012-04-12 18:09:07 +00:00
Jesse Wilson
a991e54157 Make fewer calls to out.write() when serializing strings. On one Android test, this improved serialization time of some documents by 83%.
TWEETS                              
   run          vm htmlSafe   ms linear runtime                    % 
Before app_process     true 68.7 ============================== 100% 
 After app_process     true 35.9 ===============                 52% 


                                  READER_LONG                         
   run          vm htmlSafe    ms linear runtime                    % 
Before app_process     true 439.0 ============================== 100%
 After app_process     true  74.5 =====                           17%
2012-04-12 13:24:37 +00:00
Jesse Wilson
9be0fd9ecc Make the BigDecimal and BigInteger type adapters user-overrideable. 2012-03-18 17:55:15 +00:00
Inderjeet Singh
5e3f5a6bbe Ensuring that the hash is unpredictable and well distributed.
We achieve this by using the same algorithm as the Perl version, but this implementation
is being written from scratch for license compliance.
2012-03-15 22:27:55 +00:00
Inderjeet Singh
14ebcc4ead fixed eclipse warnings 2012-03-11 21:43:38 +00:00
Jesse Wilson
4c629347da Only support string keys in string map. This rev passed all 655 applicable map tests in the Guava collections test suite. 2012-03-11 17:34:46 +00:00
Jesse Wilson
751c69c655 Support null values in StringMap 2012-03-11 15:19:01 +00:00
Jesse Wilson
ad3489f557 First steps to StringMap, an alternative to LinkedHashmap. 2012-03-11 13:54:41 +00:00
Jesse Wilson
15e7819e9a Fix testStringEndingInSlash by fixing nextNonWhitespace to always return the character at buffer[pos-1]. 2012-02-16 22:49:53 +00:00
Jesse Wilson
2c8bec27d4 Permit multiple top-level values in JsonWriter in lenient mode. Also fix some cases where we don't throw the right thing on a closed JsonWriter.
I'd prefer to not support multiple top-level values, but we support it in JsonReader and it's easier to be consistent. Kevin Hayen's patch pointed me in the right direction here, but I needed to do more work to cover some of the edge cases.

Fixes issue 397.
2012-02-12 20:42:16 +00:00
Jesse Wilson
5c978948a0 Remove some dead code. 2012-02-11 20:16:21 +00:00
Jesse Wilson
7b75efd09e Write some tests prescribed by missing code coverage. I found a bug where our nonexecute prefix code causes a problem. 2012-02-11 20:15:39 +00:00
Jesse Wilson
dd86d63436 Use inner classes for BigDecimal and BigInteger type adapters 2012-02-11 20:14:23 +00:00
Jesse Wilson
bb8dca71c4 Restore ability of instance creators to create collection and map types. We inadvertently lost this in Gson 2.0 and 2.1. Nobody noticed! 2012-01-01 15:46:33 +00:00
Jesse Wilson
6cca23c172 Get GraphAdapterBuilder working for serialization and deserialization using InstanceCreators to get a sneak peek at a value under construction. 2012-01-01 13:42:44 +00:00
Jesse Wilson
d4a1e49e46 Delete some obsolete TODOs 2012-01-01 12:42:48 +00:00
Jesse Wilson
796a381279 Kill GsonInternalAccess. Clients to this were all broken because nobody was ever assigning INSTANCE. 2012-01-01 12:42:20 +00:00
Jesse Wilson
323dfa0af5 Be strict in TypeAdapter's toJson/fromJson methods 2012-01-01 12:36:42 +00:00
Inderjeet Singh
6c78bf5247 made toJson/fromJson/toJsonTree methods public in TypeAdapter.
made Gson.getNextAdapter method public.
2011-12-31 08:52:59 +00:00
Inderjeet Singh
498049b304 updated documentation for registerTypeHierarchyAdapter to cover TypeAdapter. 2011-12-31 06:00:28 +00:00
Inderjeet Singh
46d2d79ba7 Added javadocs for type adapter registration through registerTypeAdapter method. 2011-12-31 05:32:14 +00:00
Jesse Wilson
ecdf9150f6 Hide Gson.getNextAdapter() for the current release. 2011-12-31 05:30:40 +00:00
Jesse Wilson
4057b98bab Implement all but the most difficult part of graph type adapter's deserialization. The catch is we want to return an instance that we don't have yet. It's on the stack, but we don't have a handle to it because it's inside the 'nextTypeAdapter' who is busy populating its fields. 2011-12-30 08:27:24 +00:00
Jesse Wilson
740d03ef0e Don't call setAccessible(true) on fields we won't be setting or getting.
Fixes bug 191.
2011-12-29 07:11:43 +00:00
Jesse Wilson
8d5de3136c Inline character unescaping. This saves ~10% on the READER_LONG benchmark. 2011-12-25 07:09:46 +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
Jesse Wilson
b28e518c7e Hide toJson/fromJson APIs for the 2.1 release. 2011-12-21 21:30:18 +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
f24da51ca2 Fix dangling sentence. 2011-12-16 19:00:37 +00:00
Jesse Wilson
c01fc5c935 Fix tests broken by r1078. 2011-12-16 14:12:34 +00:00
Jesse Wilson
2ef7716209 Fix a broken Javadoc link to this. 2011-12-16 05:38:16 +00:00
Jesse Wilson
214234e202 Support @SerializedName on annotations.
Fixes issue 347.
2011-12-16 05:32:50 +00:00
Jesse Wilson
b7c3e0067c Avoid local field accesses in nextString(char). This saves a modest 2%. 2011-12-14 06:07:40 +00:00
Jesse Wilson
d01d39aa26 Use locals instead of fields when figuring out the buffer's offset line and column. This saves about 2% when parsing twitter data. 2011-12-14 05:49:58 +00:00
Jesse Wilson
aa52435951 Apply an ugly optimization to save 5% on pretty printed JSON documents. This uses locals instead of fields in an inner loop to save field reads and writes. 2011-12-14 05:26:29 +00:00
Jesse Wilson
40cd660115 Always provide line and column information when a parse fails. 2011-12-13 23:42:10 +00:00
Jesse Wilson
8e8bf934f9 Inline the nesting stack to save ~20% on JsonReader parsing. 2011-12-13 04:08:48 +00:00
Jesse Wilson
61a549b74d Don't allocate exceptions in the common case. On one benchmark this improved performance by 20%. 2011-12-13 03:24:35 +00:00
Jesse Wilson
eb2230caf0 Fix nullSafe() to not infinitely recurse on non-null input. 2011-12-06 15:35:52 +00:00
Jesse Wilson
e2e672740a Fix broken test in registering competing type hierarchy adapters.
I actually tried to replicate this test but got an error "type adapters conflict" when I was doing it. I suspect the problem was that I was trying to use 'Object' as the base of my type hierarchy and that class is somehow special.
2011-12-06 15:29:48 +00:00
Inderjeet Singh
b19e187bdd Minor improvements to TypeAdapter javadocs to promote the use of nullSafe. 2011-12-06 08:32:19 +00:00
Inderjeet Singh
0b734e46e1 Incorporated code review comments from r1061.
Made nullSafe() an instance method instead of a static method.
Updated code javadoc to match Guava style.
2011-12-06 08:18:00 +00:00
Jesse Wilson
d5ed0716db Fix type adapter precedence so that last-registered wins (except for tree type hierarchy adapters, which were always last). 2011-12-06 05:09:18 +00:00
Jesse Wilson
296d843afd Implement Inder's improvements on the TypeAdapter docs 2011-12-06 04:56:46 +00:00
Inderjeet Singh
91be944022 Added a new API method nullSafe() in TypeAdapter that can be used to avoid boilerplate handling of nulls in a type adapter. 2011-12-05 19:50:49 +00:00
Inderjeet Singh
756131d869 removed Eclipse 3.7 warnings. 2011-12-04 10:24:07 +00:00
Jesse Wilson
f602bce9f5 Nice documentation for TypeAdapter. 2011-12-03 19:46:25 +00:00
Inderjeet Singh
8ee2c24f61 renamed JsonElementReader to JsonTreeReader 2011-12-03 02:37:27 +00:00
Inderjeet Singh
f3c14b4614 Added support for promoteNameToValue for JsonElementReader. 2011-12-03 02:35:46 +00:00
Jesse Wilson
8f8e69a364 Add @since tags. 2011-12-02 23:11:28 +00:00
Jesse Wilson
26ab404599 Cleanup names for TypeAdapters. 2011-12-02 22:57:30 +00:00
Inderjeet Singh
2da01fb183 Deleted deepCopy as GsonBuilder should not be designed as a reusable object. 2011-11-29 07:58:32 +00:00
Jesse Wilson
ec42d600af Decode JSON literal types eagerly and with our own decoder. Previously we relied on Double.parseDouble() to decode tokens. Since that method is expensive, we deferred calling it unless absolutely necessary. Now we decode the literal type immediately. For efficiency we decode the token right out of the char buffer. This makes things more complicated but it saves many calls to charAt(). It also opens up the possibility to deferring string creation. 2011-11-27 16:50:45 +00:00
Jesse Wilson
852cd72059 Don't allocate a whole bunch of objects each time we deserialize a map key. This saves 20% on bug 375's benchmark.
The fix here is quite distasteful; I'm adding an ugly backdoor API for MapTypeAdapterFactory to fiddle with the internal bits of JsonReader. I'd like to revisit this sooner or later, but for now I'll take the speedup.
2011-11-26 15:36:08 +00:00
Jesse Wilson
4c06b01369 Cache all computed type adapters. On one particularly violent test (issue 375) this improves performance by 77%. 2011-11-26 15:30:38 +00:00
Inderjeet Singh
ddde79c861 Added a deepCopy() method in GsonBuilder. This allows a web-service to create a pre-configured GsonBuilder and then for each request, create a Gson instance by adding type adapters to a copy.
In TypeAdapter.Factory.create() method, using the term gson to refer to the Gson instance instead of a little ambiguous context.
2011-11-25 05:40:17 +00:00
Jesse Wilson
7e47f46ac1 Remove an unused method. 2011-11-23 13:39:33 +00:00
Jesse Wilson
bc68d7293c Comment clean up. 2011-11-23 13:39:06 +00:00
Jesse Wilson
9a80d095d9 Fix a regression I introduced with the changes to type hierarchy registration. If the registered type was a raw type, we need to also match the parameterizations of that type. 2011-11-23 13:38:25 +00:00
Inderjeet Singh
1c09e24220 inlined typeAdapter and typeHierarchyAdapter methods. Added some documentation for registerTypeHierarchyAdapterFactory. 2011-11-23 09:26:44 +00:00
Jesse Wilson
1794182a56 Commit to factories as the mechanism to lookup type adapters. This uses factories for type hierarchy adapters. We keep a separate list of factories for tree-style adapters registered with registerTypeHierarchyAdapter to guarantee that these come after the non-hierarchy adapters.
This drops support for type hierarchy instance creators. I don't expect this to be a problem. We'll also detect fewer errors where multiple type adapters can serialize the same type. With APIs like getNextTypeAdapter, I think this might actually be an improvement!
2011-11-23 06:16:55 +00:00
Inderjeet Singh
d1de4cf676 renamed GsonBuilder.factory() to GsonBuilder.registerTypeAdapterFactory()
revised GsonBuilder.registerTypeAdapter/registerTypeHierarchyAdapter to take streaming type adapters as well. Removed the typeAdapter() and typeHierarchyAdapter() methods from the public API.
2011-11-22 23:56:10 +00:00
Jesse Wilson
d1cee8443f Whoops! The TreeTypeAdapter shouldn't be public API. 2011-11-22 07:47:06 +00:00
Jesse Wilson
aa2f61b7d8 Rename GsonExclusionStrategy to Excluder. The new class is its own factory, which simplifies its caller in GsonBuilder. It no longer implements ExclusionStrategy, which allows the callers to pass in a boolean for serialize/deserialize. This allows us to use one excluder for both code paths. The delegate ExclusionStrategy instances might end up not being shared so it has two lists internally. 2011-11-22 07:37:13 +00:00
Jesse Wilson
fed332906d Create a single, monolithic class to manage all exclusion strategies. This gets our file size within target of 177KiB.
I intend to follow this up with a builder for our new class to avoid multiple-argument constructor calls.
2011-11-22 06:07:18 +00:00
Jesse Wilson
4da08b0ec6 Remove two implementation classes that weren't generally useful:
- The cache interface has only one implementation. Drop the interface; we can add it back later if necessary.
 - The DefaultTypeAdapters class contains one member class. Just make that a top-level class.
2011-11-21 06:23:42 +00:00
Jesse Wilson
7def596775 Begin to tighten the ExclusionStrategy code. This replaces named classes with anonymous classes wherever we have a single instance of a type. 2011-11-21 06:14:23 +00:00
Jesse Wilson
e23973afec Smash together ReflectiveTypeAdapterFactory and its subclass. The separation was useful earlier when we were contemplating keeping Gson and MiniGson separate. 2011-11-21 05:42:30 +00:00
Jesse Wilson
f89e92aa9f Tighten up some of the fields naming policy code. The main thrust of this change is replacing classes like UpperCaseNamingPolicy with the corresponding method calls. Classes like CompositeFieldNamingPolicy are replaced by sequences of method calls. This also replaces unit tests with functional tests.
One nice benefit of this is a 3%/5.7KiB reduction in the size of gson.jar to 184KiB.
2011-11-21 05:08:23 +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
a00c5ff9f1 Simplify inner strategy in LongSerializationPolicy. 2011-11-20 20:16:46 +00:00
Jesse Wilson
1540201713 Remove unused interface 2011-11-20 20:15:45 +00:00
Jesse Wilson
d391584d48 Register Gson 1.x tree-style adapters in the TypeAdapter.Factory list rather than in the ParameterizedTypeHandlerMap.
The motivation for this change is to give tree-style adapters precedence order in registration. This fixes the test I committed earlier today, where registration order was not honored.

This renamed ParameterizedTypeHandlerMap to the shorter 'TypeMap'. For type adapters, this is now only used for type hierarchy. We still need non-hierarchy support in TypeMap for instance creators; I'll be looking for workarounds to see if further simplification is possible here.
2011-11-20 19:55:01 +00:00
Jesse Wilson
777e17c723 No more system type adapters. 2011-11-20 18:03:46 +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
Joel Leitch
a92cf394e8 Fix compile issues found during release. 2011-11-13 20:04:29 +00:00
Joel Leitch
2c19c43905 Adding Jesse's name to the JsonElementReader file. 2011-11-13 00:27:57 +00:00
Joel Leitch
2cbddbbbc5 - Remove unnecessary catch block 2011-11-13 00:04:39 +00:00
Jesse Wilson
172143df7c Removing JsonObject.deepCopy() and JsonArray.deepCopy() 2011-11-12 23:32:44 +00:00
Jesse Wilson
0ac36805c2 Remove an unnecessary cast from example code. 2011-10-24 14:14:34 +00:00
Jesse Wilson
016261d9cf Throw JsonParseException in event of binding failures like type mismatches. 2011-10-24 01:32:46 +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
Jesse Wilson
052c9ce0ce Honor our 'ignore nulls' policy when converting objects to JSON trees. 2011-10-23 20:28:04 +00:00
Jesse Wilson
290fb69a50 Provide more diagnostics when a constructor fails. 2011-10-22 20:22:47 +00:00
Jesse Wilson
94d59b550e Give a nice toString on type adapter factories to make debugging easier. 2011-10-22 19:26:15 +00:00
Jesse Wilson
90c9eadda1 custom-collections 2011-10-22 19:25:30 +00:00
Inderjeet Singh
339d3dd4d0 The real reason for this CL is to claim commit #1000 :)
Tiny performance enhancement: Reordered type orders to move up String and Integer which are likely to be most common fields.
2011-10-20 21:42:45 +00:00
Inderjeet Singh
31964507c1 Updated SuppressWarnings annotations to Eclipse 3.6/3.7 which is unfortunately incompatible with Eclipse 3.5 (rawtypes vs unchecked)
This CL eliminates all eclipse warnings.
2011-10-20 21:32:46 +00:00
Jesse Wilson
194c18d20c Be backwards-compatible for serialization of maps whose keys aren't primitives. 2011-10-20 04:24:27 +00:00
Jesse Wilson
0e02cbb33e Nulls are here to stay. Sigh. 2011-10-14 03:20:05 +00:00
Jesse Wilson
5db4caeec5 A whole bunch of tests for support for null elements.
Fixes bug 369
2011-10-14 03:17:12 +00:00
Inderjeet Singh
c4a2291866 Deleted unused fields. 2011-10-02 20:45:26 +00:00
Jesse Wilson
65df3b97ba Add a type adapter for JsonElement, so it serializes just like everything else.
Fixes issue 362.
2011-10-02 16:59:56 +00:00
Jesse Wilson
01661426f9 Fix broken example.
Fixes bug 360.
2011-10-01 04:09:38 +00:00
Jesse Wilson
de727d8c48 Delete dead code found by coverage 2011-10-01 02:04:48 +00:00
Jesse Wilson
38ce53766e More consistency on serializeNulls: we never emit the empty string for top-level objects. 2011-10-01 01:10:11 +00:00
Jesse Wilson
de835d4dcd Roll back JsonSerializationContext and JsonDeserializationContext to their 1.7.2 API. 2011-10-01 00:58:25 +00:00
Jesse Wilson
70abd0ba87 Finishing touches on JsonElementWriter 2011-10-01 00:42:28 +00:00
Jesse Wilson
349c01e861 JsonElementWriter NaN, -Infinity, Infinity 2011-10-01 00:35:51 +00:00
Jesse Wilson
ed2b25ddef Don't serialize nulls in JsonElementWriter if setSerializeNulls(false) 2011-10-01 00:22:33 +00:00
Jesse Wilson
9b7b49bf0f Implement JsonElementWriter.close() 2011-10-01 00:12:36 +00:00