typhoid / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

pre-escaped valid string to be returned as a JsonElement #514

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Attempt customizing the  string(String value) throws IOException method of 
the JsonWriter

What is the expected output? What do you see instead?
GSON would always re-perform string escaping even if I would want to avoid it 
for a specific performance reason.

What version of the product are you using? On what operating system?
Code transitioning from Gson 1.5 -> 2.2.4
Windows 

Please provide any additional information below.

(originally from StackOverflow: 
http://stackoverflow.com/questions/15486137/gson-2-2-2-json-custom-jsonwriter-fo
r-jsonelement-to-avoid-escaping-string)

I have a use case where I have a pre-escaped valid string to be returned as a 
JsonElement. However, the JsonElement internally using the JsonWriter would 
parse through the string to attempt doing string escaping / character 
replacement.

See 
https://code.google.com/p/google-gson/source/browse/trunk/gson/src/main/java/com
/google/gson/stream/JsonWriter.java

private void string() method

I would like to avoid doing this for performance reasons as my String element 
is pre-escaped.

I did a search and found this use case to be similar: 
https://code.google.com/p/google-gson/issues/detail?id=239

Although the solution in the above link would work with gson1.5, the Escaper 
class has been removed in the latest gson (2.2.2).

How can I extend the JsonElement (or the JsonWriter internal to it) such that I 
can avoid the JsonWriter string replacement overhead for a specific Type?

Original issue reported on code.google.com by anmolsha...@gmail.com on 17 May 2013 at 4:35