Commit Graph

705 Commits

Author SHA1 Message Date
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
Sebastian Chlan
299ee89852 Add tests to demonstrate the issue
Run the FieldNamingTest with the JVM options: `-Duser.language=tr
-Duser.region=TR`
2015-06-09 15:12:38 +01:00
Inderjeet Singh
fdaa6b05c4 ensuring that the type field is written by runtime type adapter 2014-12-10 22:57:08 +00:00
Inderjeet Singh
7d96ce8d6d fixed tests to take care of stackTrace element appearing sometimes 2014-12-10 22:43:44 +00: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
1de2ace065 removed eclipse warnings. updated maven plugins to the latest versions 2014-11-16 20:45:01 +00:00
Inderjeet Singh
60b2370c74 added a test for RuntimeTypeAdapterFactory using JsonAdapter annotation 2014-11-11 22:04:20 +00:00
Inderjeet Singh
e652ec0dd9 revised a test to validate that we can query a delegate adapter from typeadapterfactorie registered in JsonAdapter 2014-11-11 02:02:56 +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
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
ea17ccc651 Restore missing fails. 2014-08-12 21:06:56 +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
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
Inderjeet Singh
14ba59fa88 code review fixes. Moved getFirstArgument() method from $Gson$Types to GsonTypesTest. 2014-05-19 17:34:25 +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
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
eaaa2a1b4f added functional tests for applying JsonAdapter annotation on Fields. 2014-03-09 07:31:02 +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
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
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
Joel Leitch
7c9fd53c78 Fix test that expects an exception to fail if no exception is thrown 2013-05-03 15:34:58 +00:00
Joel Leitch
b88e0e9395 Test to expose edge doubling and rehashing bug in LinkedHashTreeMap. 2013-05-03 15:13:30 +00:00
Joel Leitch
8e8bb9c688 Added test for comments inside a string value. 2013-04-14 21:36:47 +00:00
Inderjeet Singh
a3f11150cc removed more eclipse warnings 2013-04-12 20:12:12 +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
83e1f45653 Re-add non-comparable key tests to LinkedHashTreeMap. 2013-04-04 22:29:29 +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
6a69c603c0 Permit serialization of "Class" fields, but only if they're null. 2013-02-04 15:52:51 +00:00
Joel Leitch
5af92f1736 Additional changes to a map test with "null" string key. 2013-01-14 22:18:07 +00:00
Joel Leitch
e5b9b8eb81 Minor addition to the JsonNullTest. 2013-01-14 18:40:23 +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
Jesse Wilson
b4d51db776 Add a test case for a problem reported on the group.
https://groups.google.com/d/topic/google-gson/EBmOCa8kJPE/discussion
2012-10-29 16:30:33 +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
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
714ac8e643 added tests for using intercept in fields and lists. These tests are currently failing. 2012-10-11 20:29:40 +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
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
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
b0a172944a More number parsing improvements. 2012-08-27 03:17:41 +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
b96d2d9837 Support non-execute prefixes. 2012-08-26 19:31:06 +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
Inderjeet Singh
42e35e9f90 updated oss-parent version to 7 in gson-extras pom.
fixed some eclipse warnings.
2012-08-01 20:57:51 +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
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
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
e9b576c456 removed unused import 2012-05-06 07:19:23 +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
7b61e784c0 Remove testParameterizedMapSubclassDeserialization that never passed. We'll eventually add an equivalent to the extras/ package. 2012-04-12 18:15:56 +00:00
Jesse Wilson
9be0fd9ecc Make the BigDecimal and BigInteger type adapters user-overrideable. 2012-03-18 17:55:15 +00:00
Inderjeet Singh
14ebcc4ead fixed eclipse warnings 2012-03-11 21:43:38 +00:00
Inderjeet Singh
15c2ae7548 Updated map subclass deserialization test to illustrate a failing condition.
Gson currently uses LinkedHashMap for an instance if a Map subclass does not define a default constructor.
2012-03-11 21:37:13 +00:00
Jesse Wilson
751c69c655 Support null values in StringMap 2012-03-11 15:19:01 +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
f40ac23e88 Write a test recommended by missing code coverage on TypeAdapter 2012-02-11 20:16:05 +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
a0afec71ff Test case to demonstrate no such crash as reported in issue 408. 2012-02-11 18:19:54 +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
323dfa0af5 Be strict in TypeAdapter's toJson/fromJson methods 2012-01-01 12:36:42 +00:00
Jesse Wilson
641590b5b6 Fill in some gaps in ExclusionStrategy's test.
Changes to GsonInternalAccess should have broken exclusion strategies, but didn't. Adding these tests cause the expected breaks.
2012-01-01 12:34:47 +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
4cb1b88115 Test for registerTypeHierarchyAdapter() using Date.class
Fixes issue 352.
2011-12-29 07:27:33 +00:00
Jesse Wilson
6d2cf4a853 Test for excludeFieldsWithModifiers().
Fixes issue 324.
2011-12-29 07:17:36 +00:00
Jesse Wilson
8d5de3136c Inline character unescaping. This saves ~10% on the READER_LONG benchmark. 2011-12-25 07:09:46 +00:00
Inderjeet Singh
2cd3f9707f Incorporated feedback from r1082 2011-12-23 16:11:12 +00:00
Inderjeet Singh
bd937fe7b5 A type adapter for Class that throws an UnsupportedOperationException. 2011-12-22 22:31:43 +00:00
Jesse Wilson
13c1946621 More tests that skipValue() is no less strict. 2011-12-21 21:43:55 +00:00
Jesse Wilson
b28e518c7e Hide toJson/fromJson APIs for the 2.1 release. 2011-12-21 21:30:18 +00:00
Jesse Wilson
dd9ae67af5 Test that skipValue is strict on unquoted strings. 2011-12-21 20:40:33 +00:00
Inderjeet Singh
4b8fd66c9d Added a test for issue 389 2011-12-16 17:21:31 +00:00
Jesse Wilson
214234e202 Support @SerializedName on annotations.
Fixes issue 347.
2011-12-16 05:32:50 +00:00
Jesse Wilson
d891661c4a Apply locale fix for date type adapter test.
Fixes issue 381.
2011-12-16 04:57:22 +00:00
Jesse Wilson
eb2230caf0 Fix nullSafe() to not infinitely recurse on non-null input. 2011-12-06 15:35:52 +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
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
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
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
a069f4d883 Added a failing test that demonstrates regression on tree-style type adapters.
In this test, we are registering a tree type adapter for Id but it never gets invoked. Instead, the reflective type adapter gets invoked causing an exception.
2011-11-23 09:49:03 +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
Jesse Wilson
3cbe355cb6 Test precedence of type hierarchy adapters. 2011-11-23 05:13:17 +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
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
0ff7d980c5 Adjust LruCacheTest to use the Map API 2011-11-21 06:26:30 +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
e9521471aa Fix typo: Paramterized was spelled wong. 2011-11-20 20:31:10 +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
3f5caea95e New (failing) test to demonstrate that we're broken with precedence of streaming vs. nonstreaming type adapters. 2011-11-20 15:35: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
172143df7c Removing JsonObject.deepCopy() and JsonArray.deepCopy() 2011-11-12 23:32:44 +00:00
Jesse Wilson
00946277e8 Track change in thrown exception. 2011-10-24 05:03:06 +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
c226bd4f3f Tests to illustrate differences between GSON 1.7 and 2.0 2011-10-23 22:44:13 +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
90c9eadda1 custom-collections 2011-10-22 19:25:30 +00:00
Inderjeet Singh
905b7ebccc Using single quote in JSON that would be deserialized. This makes the JSON easier to read. 2011-10-20 21:35:39 +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
cc5cbe5a1f Integration test for long serialization policy. 2011-10-20 04:57:58 +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
5db4caeec5 A whole bunch of tests for support for null elements.
Fixes bug 369
2011-10-14 03:17:12 +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
3a3870591e Tests to demonstrate that GSON 2 fixes some user-reported bugs. 2011-10-02 15:18:12 +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
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
Inderjeet Singh
d3f927eb42 Pure refactorings:
Replaced DEFAULT_SERIALIZERS, DEFAULT_DESERIALIZERS and DEFAULT_INSTANCE_CREATORS with a single EMPTY_MAP.
Removed obsoleted TODO from Gson.
made ParameterizedTypeHandlerMap.makeUnmodifiable a builder method that returns this instance.
2011-09-30 17:56:40 +00:00
Inderjeet Singh
47a36fd095 Fixed Eclipse warnings 2011-09-30 17:08:35 +00:00
Jesse Wilson
bb7f0b6bb0 Adopt JsonElementWriter in GSON.
Add setSerializeNulls() to JsonWriter, so nulls can be skipped from serialization. This does not yet impact JsonElementWriter.

One change in behavior: if the only value is skipped, we now emit "null" rather than "".
2011-09-30 07:08:44 +00:00
Jesse Wilson
364de80611 Stream to a DOM 2011-09-30 06:32:33 +00:00
Jesse Wilson
d26c818918 New streaming writer writes to DOMs 2011-09-30 06:26:46 +00:00
Jesse Wilson
6c0566bd22 Start using JsonElementReader in TypeAdapter.
Also fix strict handling of NaN and Infinity
2011-09-30 03:47:30 +00:00
Jesse Wilson
1bb01055f0 Tests for JsonElementReader.close 2011-09-30 03:31:44 +00:00
Jesse Wilson
9ce9c62b44 Tests for JsonElementReader 2011-09-30 03:25:41 +00:00
Jesse Wilson
bd2a0ac466 Support JsonReader API on DOM objects.
This still needs test coverage & documentation but it appears to work!
2011-09-30 00:44:37 +00:00
Inderjeet Singh
423d18feb5 Revised test to take into account known problems with JsonElement that holds BigInteger values. 2011-09-29 22:18:16 +00:00
Inderjeet Singh
2541e658f7 Fixed com.google.gson.functional.VersioningTest.testIgnoreLaterVersionClassDeserialization by changing Gson behavior incompatibly (but more consistent).
GSON 1.x applies different rules for versioning for classes vs fields. So, if you deserialize a
   JSON into a field that is supposed to be skipped, the field is set to null (or default value). 
   However, if you deserialize it to a top-level class, a default instance is returned.
GSON 2.x returns null for the top-level class.
2011-09-29 22:15:37 +00:00
Jesse Wilson
8b21c7770b Use the same behavior in all situations when an InstanceCreator returns a subclass.
Previously we would set the field if the created instance is being assigned to a field of another object. We wouldn't set it when the created instance is a collection element or the top-level object.
2011-09-29 16:38:24 +00:00
Jesse Wilson
4d0775ce8e Let the runtime throw on circular references 2011-09-28 19:38:43 +00:00
Jesse Wilson
46e65a77c5 Convert RuntimeTypeAdapter to a TypeAdapterFactory; this avoids the need for serializeDefault() 2011-09-28 19:14:46 +00:00
Jesse Wilson
2236c95c37 Death to serializeDefault and deserializeDefault 2011-09-28 18:00:34 +00:00
Inderjeet Singh
cebda2b119 Fixed MapTest.testInterfaceTypeMapWithSerializer. This test for relying on JsonElement.toString() to have same behavior as gson.toJson(JsonElement). However, gson.toJson() skips nulls by default whereas JsonElement.toString() does not. 2011-09-27 15:38:02 +00:00
Inderjeet Singh
2780a2a9bf Fixed eclipse warnings. 2011-09-16 06:03:16 +00:00
Inderjeet Singh
882c14a367 Added support in Gson for serializing/deserializing from primitive char.
Created a new class for character/char tests, PrimitiveCharacterTest. This is the start of breaking down PrimitiveTest into smaller chunks.
When MiniGson can not find a type adapter for a type, revised the message to say can't handle instead of can't serialize.
2011-09-16 05:52:32 +00:00
Inderjeet Singh
fd502f4e79 removed unused method. 2011-09-16 05:41:04 +00:00
Inderjeet Singh
c71e61cf48 Converted EnumTypeAdapter to new style.
Got rid of default Hierarchy Serializer/Deserializers from DefaultTypeAdapters.
Got rid of methods for gettting default serializers/deserializers/instance creators. Instead we reuse the static final instances.
Fixed warnings in TypeAdapters where a parameterized type T was hiding the parameterized T in methods.
Removed support to unwrap single element array of enums into enum values. Also removed the test that verifies this behavior.
2011-09-16 05:40:05 +00:00
Joel Leitch
b90b43ea47 A few minor fixes and one incompatible Java 1.6 API call. 2011-09-16 04:55:52 +00:00
Inderjeet Singh
6b2c275b5c Deleted Long, Float and Double serializers from legacy DefaultTypeAdapters. This stuff is not invoked anymore as the MiniGson takes care of it. 2011-09-16 04:06:33 +00:00
Jesse Wilson
51a9596d06 Make Dates test slightly more robust to time of day issues. The test still fails outside of PST when run as a part of a larger suite because GSON captures a static snapshot of the system time zone at GSON-creation time. 2011-09-12 06:02:48 +00:00
Jesse Wilson
a98d6eae47 Fix the map type adapter to support array serialization natively. 2011-09-12 05:51:17 +00:00
Jesse Wilson
25c6ae177b Down to 22 failing tests.
Consolidated all of the different code paths that we use to construct instances. We now have an ObjectConstructor class that knows what type it constructs; this means that we don't need to ever do reflection to lookup a constructor at construction time.

Cleaned up some buggy type adapters, particularly around handling of null.

Removed dead code for object graph navigation.

Moved some classes into 'internal' so they are visible to the 'bind' subpackage.

Turned some TypeAdapterFactory/TypeAdapter pairs inside out so that the TypeAdapter is now the inner class. This is necessary so that the factories can take parameters.

Added an API to request the 'next' type adapter for a type. This allows type adapters to compose other type adapters. We're using this in two places:
 - where the user has excluded a type from serialization but not deserialization, we need to use the "default" deserialization but interpose null on serialization. We create a type adapter that delegates for one and returns null for the other.
 - similarly when a DOM type serializer is registered but no deserializer, or vice versa.
This is the biggest change to the MiniGson core.

For backwards compatibility, return null for the empty string.

Simplify JsonSerializationContext/JsonDeserializationContext to simply call through to GSON. SerializeDefault is currently unsupported.

More useful error messages when calling getAsBoolean on a JsonNull.

Remove currently unused MemoryRefStack. We might need this back again, though wiring it back in will be much more difficult because we don't interject ourselves between the users' various type adapters.
2011-09-11 07:04:56 +00:00
Jesse Wilson
cdd5d80b85 Support writing maps with non-string keys 2011-09-09 08:17:20 +00:00
Jesse Wilson
2ee89879e1 New failing test to show that JsonPrimitive.equals() is broken for values that are out of 'long' range 2011-09-09 07:58:52 +00:00
Jesse Wilson
e756608568 Forbid custom serializers for primitive types (so we can avoid boxing in the reflective and array adapters) 2011-09-09 06:26:21 +00:00
Inderjeet Singh
fede584b98 Gson 2.0 converts JSON with type Object.class into something meaningful such as a Collection of primitives or Maps. Updated tests for the new behavior.
Changed $Gson$Types.getCollectionElementType to handle wild-card sub-classes of collections and raw collections.
2011-09-09 06:23:17 +00:00
Jesse Wilson
9424949245 Don't unwrap single-element String arrays 2011-09-09 05:41:35 +00:00
Jesse Wilson
da67003eef GSON 1.x uses arbitrary precision for primitive type conversion (so -122.08e-2132 != 0)
GSON 2.x uses double precision (so -122.08e-2132 == 0)
2011-09-09 05:23:01 +00:00
Jesse Wilson
a7e9ac3612 Don't support oversized values like 30-character integers 2011-09-09 05:11:59 +00:00
Jesse Wilson
e19672d0a3 Throw the right exceptions when primitives fail to parse. 2011-09-09 05:04:24 +00:00
Jesse Wilson
9db0c53217 Adapt bytes 2011-09-09 04:39:29 +00:00
Jesse Wilson
f67940cb63 Retire two old bad features
- overriding primitive type adapters
 - auto unwrapping of single element arrays
2011-09-09 04:20:25 +00:00
Jesse Wilson
3aeb70e030 Adapter for Object.class 2011-09-09 03:31:16 +00:00
Inderjeet Singh
9b6954decd Additional tests to verify handling of bytes. 2011-08-26 01:11:50 +00:00
Inderjeet Singh
64dc53ffc4 Added support for runtime type determination while serializing collections and its subclasses.
This currently doesn't work since Gson register a hierarchy type adapter for Collections that takes precedence over this.
2011-08-04 23:55:52 +00:00
Jesse Wilson
aa067056c3 Restore support for long serialization policy. 2011-08-04 22:57:36 +00:00
Inderjeet Singh
5c620c7e0a Changed Gson behavior to reject duplicate fields in a class. 2011-08-03 03:05:12 +00:00
Inderjeet Singh
d70fb90ef7 Added methods to convert to JsonElement in TypeAdapter.
Using lenient mode while working with Gson.
Handling nulls while invoking legacy Gson type adapters.
2011-08-03 02:40:18 +00:00
Jesse Wilson
60e6ed912d Promote MiniGson to gson.internal.bind 2011-08-03 00:25:10 +00:00
Jesse Wilson
befcfd908b Skip a byte order mark (BOM) if it exists.
http://code.google.com/p/android/issues/detail?id=18508
2011-07-20 18:57:30 +00:00
Jesse Wilson
415437810a Include line and column position in error messages. 2011-07-18 19:26:02 +00:00
Jesse Wilson
9cf579ef01 Use Streams instead of Escaper.
Fixes issue 345.
2011-07-12 23:50:00 +00:00
Jesse Wilson
d3a4b48ad9 Unconditionally escape unicode newline characters.
Fixes issue 341.
2011-07-12 16:05:22 +00:00
Joel Leitch
7dca724292 Fixing import order. 2011-07-12 04:15:46 +00:00
Jesse Wilson
807aa97ee7 Don't use ambiguous timezone names.
Fixes bug 331.
2011-07-01 22:00:45 +00:00
Jesse Wilson
937019651a Trailing comma tests 2011-07-01 21:36:05 +00:00
Inderjeet Singh
62675b7f46 Added serializeDefault and deserializeDefault methods in contexts that only invoke system type adapters on the top-level object.
With this, the RuntimeTypeAdapterTest passes.
2011-07-01 21:29:20 +00:00
Inderjeet Singh
5f4e88f62a More tests to ensure that serialization works for parameterized types like A<B<C<D>>> without the need to specify type in toJson() 2011-06-25 20:14:09 +00:00
Inderjeet Singh
d347128e6f Implemented support for serializing objects of type Bar<Foo> without the need to specify their type explicitly in toJson method. 2011-06-25 20:04:14 +00:00
Inderjeet Singh
ef2f73180b added tests to illustrate and validate that Gson can serialize parameterized types without the need of explicit type token. 2011-06-25 19:43:05 +00:00
Inderjeet Singh
9196b23251 Refactoring: Separated type handler maps into two types: one for system-specified handlers and one for user-specified. system-specified handlers are the ones that Gson comes with (DefaultTypeAdapters). 2011-06-24 21:52:59 +00:00
Jesse Wilson
f74dffc6fd Add deepCopy to JsonArray and JsonObject.
Resolves issue 301.
2011-06-17 21:46:28 +00:00
Joel Leitch
c9ee7adcc5 Start using JsonNull.INSTANCE everywhere and remove creation method. 2011-06-03 19:02:28 +00:00
Inderjeet Singh
60e7c481fd Added complex map serialization tests in case the Map is defined with TypeVariables. 2011-05-30 09:38:38 +00:00
Inderjeet Singh
f2eb76eac9 removed deprecation warnings by using JsonNull.INSTANCE 2011-05-25 16:48:39 +00:00
Inderjeet Singh
b85daafb08 suppressed unchecked warning 2011-05-11 21:43:47 +00:00
Inderjeet Singh
0bcd1b341f Revised Gson to refuse to deserialize floating point numbers into integer types.
This is probably a break from the past: previous versions of Gson allowed truncating a floating point into a long or int. However, it wasn't consistent in this behavior. It disallowed converting a BigDecimal value into BigInteger, int or long. Refusing to deserialize such values is aligned with fail-fast approach of uncovering bugs.
2011-05-04 23:26:22 +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
4efeef1893 Make test a little more complex to show it actually fixed the bug. 2011-04-20 22:32:13 +00:00
Joel Leitch
f291c4d33e Fix a bunch of preserve-type issues:
- Issue 205
- Issue 294
- Issue 318
2011-04-20 22:27:51 +00:00
Joel Leitch
cf3615e38c Adding tests to verify 294. 2011-04-19 22:18:25 +00:00
Inderjeet Singh
e60274ed35 Added tests to ensure that subclass objects that are of a parameterized type are serialized per their declared type in lists or maps. 2011-04-19 20:49:48 +00:00
Inderjeet Singh
40045dc2e4 Added tests to ensure that subclass objects are serialized per their real type in lists or maps.
Currently, this doesnt happen for List and hence the test is marked as disabled.
2011-04-19 20:26:16 +00:00
Joel Leitch
d2cf574e86 Adding unit-tests to verify bugs. 2011-04-15 06:33:09 +00:00
Joel Leitch
c894fb6c23 Default support for BitSet. As well, provide more flexibility on getAsBoolean for a JsonPrimitive. 2011-04-14 02:42:47 +00:00
Joel Leitch
97d00f4930 Add test to verify issue 309. 2011-04-13 16:14:54 +00:00
Joel Leitch
4917fc7f76 Lift restriction on naming when using the "@SerializedNamed" annotation.
Fix for Issue 290.
2011-04-12 17:29:19 +00:00
Joel Leitch
49e7ee05fc Fix method name by making it singular. 2011-04-11 18:44:19 +00:00
Inderjeet Singh
4bd261ae06 Made FieldNamingStrategy2 and its corresponding builder method package-private. 2011-04-07 17:41:35 +00:00
Inderjeet Singh
05ae10a144 removed the constructor in FieldAttributes that was only used in tests. 2011-04-06 00:51:01 +00:00
Joel Leitch
ddb0c8c825 Minor formatting fixes. 2011-04-06 00:43:57 +00:00
Inderjeet Singh
c8bd121db2 Renamed $Preconditions to $Gson$Preconditions and $Types to $Gson$Types.
Marked the two private classes in $Types as final.
2011-04-06 00:26:57 +00:00
Joel Leitch
b4eb810347 Comments for r766. 2011-04-06 00:02:40 +00:00
Joel Leitch
f36c1bc222 Very minor cleanup. 2011-04-04 23:17:43 +00:00
Joel Leitch
2fb8c92812 Use more specific type for map serialization if possible. 2011-04-04 23:13:31 +00:00
Inderjeet Singh
542a17c3bc Incorporated comments from r710 2011-04-04 22:48:34 +00:00
Inderjeet Singh
56b7ab1b71 Incorporated feedback from r718 2011-04-04 22:23:51 +00:00
Inderjeet Singh
feb9617bf0 Incorporated comments from r726 2011-04-04 22:09:51 +00:00
Inderjeet Singh
a147164852 incorporated feedback on r721 2011-04-04 21:43:24 +00:00
Inderjeet Singh
1a9a54dcc2 incorporated review comments from r768 2011-04-04 21:27:37 +00:00
Joel Leitch
21ddfc9b12 Show default serialization and deserialization works with subclasses of an enum type. 2011-04-04 19:19:46 +00:00
Joel Leitch
5af0b16641 Updating Map tests. 2011-04-04 19:07:20 +00:00
Inderjeet Singh
9c894c7485 switched from accessing field to an accessor method for access in tests.
Strangely, this fixes the broken tests in the continuous build.
2011-03-31 18:57:55 +00:00
Inderjeet Singh
5bc80cd693 Moved Cache, LruCache, Pair, Primitives and UnsafeAllocator to com.google.gson and made them package private. 2011-03-30 13:59:06 +00:00
Jesse Wilson
46a8e9b411 Test to demonstrate that we've fixed issue 302.
http://code.google.com/p/google-gson/issues/detail?id=302
2011-03-29 21:48:03 +00:00
Jesse Wilson
f718784f33 Use the date format for java.sql.Date and java.sql.Timestamp.
Fixes issue 230.
2011-03-29 21:36:19 +00:00
Jesse Wilson
4efb133b4a bling bling
Prefix internal classes with $ to prevent them from interfering with IDE's auto import functionality.
2011-03-29 21:24:26 +00:00
Joel Leitch
454f58a7b1 Adding in instance creator to instantiate the concrete Collection or Map class if known, otherwise fallback to a default instance.
Also, added some caching as part of the default constructor lookups.
2011-03-29 16:57:28 +00:00
Inderjeet Singh
337d89cf3f Removed ObjectNavigatorFactory 2011-03-24 20:19:41 +00:00
Inderjeet Singh
13dc7b6f02 Made ObjectNavigator a reusable object. We now use just one instance of ObjectNavigator instead of creating one for each field/object. 2011-03-24 18:41:45 +00:00
Inderjeet Singh
005c93e383 removed unused no-args constructors 2011-03-23 18:48:03 +00:00
Joel Leitch
861e047a62 Create an "internals" package for classes that we do not want to share, but is needed across multiple pacakges.
As well, move non-Gson specific classes, such as Preconditions, to this new "internals" package.
2011-03-21 22:30:35 +00:00
Jesse Wilson
657688ca79 Test that the date format is honored, even in a collection.
http://code.google.com/p/google-gson/issues/detail?id=230
2011-03-21 22:10:33 +00:00