sefasdfasd / google-gson

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

Should be pass EMPTY DOCUMENT without throwing exception #421

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
from this code 
http://code.google.com/p/google-gson/source/browse/trunk/gson/src/main/java/com/
google/gson/stream/JsonWriter.java?r=615#416

It only check for document to end properly, but sometime we just open 
JSonWriter but later logic don't write anything so we just want to close then 
it will throw exception

Which I think is no need, it should be check or if peek() != 
JsonScope.EMPTY_DOCUMENT too, or changing JsonScope to drop EMPTY and NONEMPTY, 
just check that scope stack is empty and that's all

Original issue reported on code.google.com by thainayu on 19 Mar 2012 at 7:55

GoogleCodeExporter commented 9 years ago
An empty string isn't a valid JSON document. Two options:
- just catch the exception.
- begin your document with a beginArray() call (unconditionally) and end it 
with an endArray() call. That'll guarantee your document is never invalid, even 
if your array is empty.

Original comment by limpbizkit on 11 Apr 2012 at 8:48

GoogleCodeExporter commented 9 years ago
THIS IS NOT JSONDOCUMENT BUT A JSONWRITER

If the logic is creation of "Writer" then we may not write anything and we 
close "The Writer" so there are no document

Making a writer then force it to create document immediately is wrong logic in 
the first place. Think about OOP then "Writer" and "Document" is difference 
object. Creation and Closing "Writer" should not always strongly relate to 
"Document"

Original comment by thainayu on 12 Apr 2012 at 6:37