Commit Graph

25 Commits

Author SHA1 Message Date
Johannes Frohnmeyer dc4e61ac7b
Several breaking changes 2022-05-17 21:20:10 +02:00
Johannes Frohnmeyer ccf30b23e8 newline before comment 2022-05-17 06:15:12 +00:00
Johannes Frohnmeyer 35241fc7b2
Add comment support 2022-05-12 23:23:14 +02:00
Marcono1234 49ddab9eeb
Add CodeQL GitHub code scanning workflow (#2076)
* Add CodeQL GitHub code scanning workflow

* Only compile main sources for code scanning

* Move test .proto  files to test sources

`annotations.proto` also seems to be only relevant for tests because the test
explicitly registers them as extensions. By default the Proto adapter does not
consider them.

* Address some code scanning findings

* Fix some more findings
2022-02-17 18:40:40 -08:00
Marcono1234 e2e851c9bc
Add LazilyParsedNumber default adapter (#2060)
* Add LazilyParsedNumber default adapter

* Validate JsonWriter.value(Number) argument

* Fix incorrect JSON number pattern, extend tests
2022-01-28 11:26:28 -08:00
David Maplesden 3958b1f78d Prefer writing chars instead of strings of length one (#1576)
This results in a noticeable performance improvement with most writer
implementations (including BufferedWriter).
2019-09-18 10:33:49 -07:00
Degubi bac26b8e42 Optimize array copies 2019-03-05 12:12:04 -05:00
Mike ada597e69a value(double) can write NaN and infinite values when lenient, as value(Number) does (#1093)
* Added test which shows that lenient JsonWriter fails writing infinite primitive doubles, but does not fail writing boxed doubles, as stated in #1090.

* Fixed JsonWriter#value(double) to write infinite and NaN values when lenient, as JsonWriter#value(Number) does. (fixes #1090)
2017-05-31 09:50:44 -07:00
Jake Wharton 59edfc1caf Add boxed boolean value() overload.
When calling value() with a Boolean overload resolution would choose value(boolean) which would throw an NPE on null. The other boxed types are all numbers which would resolve to value(Number) and behave correctly.
2016-04-22 19:52:38 -04:00
Jake Wharton c8627c8ab8 Update reader and writer for RFC 7159. 2016-01-18 15:07:33 -05:00
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
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
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 1c7aee40f3 Implement Flushable. 2012-06-30 02:46:26 +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 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 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 d26c818918 New streaming writer writes to DOMs 2011-09-30 06:26:46 +00:00
Jesse Wilson d3a4b48ad9 Unconditionally escape unicode newline characters.
Fixes issue 341.
2011-07-12 16:05:22 +00:00
Inderjeet Singh 2b993d83b6 Made the GsonBuilder registerTypeHierarchyAdapter a public method.
Updated the Gson version number to 1.6 and added @since tag for the new classes
2010-10-27 23:53:09 +00:00
Jesse Wilson 202bbfeef0 Fixing the Java 1.5 build. 2010-09-02 09:29:26 +00:00
Jesse Wilson 747e3c3051 Support mixed streaming and databinding with new APIs. 2010-09-02 00:15:23 +00:00
Jesse Wilson 486820f515 Fix some test problems.
JsonWriter was using suboptimal escape characters for newlines etc: unicode escapes rather than \x escapes.

JsonObjectTest was banning empty and whitespace-only keys. These values are permitted as of r585.
2010-08-28 08:18:13 +00:00
Jesse Wilson ff7aa3f331 Escape only the required characters when emitting JSON. This means that instead of emitting
["foo\nbar", "baz"]

we'll emit this:

  ["foo
bar", baz"]

This simple change measured about ~35% faster for in-memory writes!
2010-08-28 07:29:22 +00:00
Jesse Wilson 765a9f1ecd Brand new classes for streaming JSON efficiently.
Notable features:
 - Efficiency. The parser is faster than the current javacc parser. It's also faster than popular libraries for JSON streaming.
 - Toggle lenient/strict
 - Toggle pretty/compact
 - Friendly error messages on bad JSON
 - GSON-quality Javadoc
 - Non-execute prefix handling

This doesn't wire JsonReader up into Gson just yet. That's coming soon...
2010-08-26 08:44:02 +00:00