sinamdar2015 / google-gson

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

Invalid JSON parsed without any notification/exception. #422

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create default instance of Gson.
2. Parse file with fromJson method.
3. Result list of elements has one empty (excessive) element in the end.

What is the expected output? What do you see instead?
ParsingException with message about invalid JSON data.

What version of the product are you using? On what operating system?
gson-2.1.jar on Android

Please provide any additional information below.
Attached JSON was reported as invalid on http://jsonlint.com/

Original issue reported on code.google.com by mst...@gmail.com on 23 Mar 2012 at 9:11

Attachments:

GoogleCodeExporter commented 9 years ago
When you use Gson.fromJson(json, type), it parses in lenient mode. Changing 
this would break backwards compatibility.

You can work around this by calling Gson.getAdapter(type).fromJson(json) which 
will do a strict parse.

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

GoogleCodeExporter commented 9 years ago
In such case it would be nice to have possibility to change lenient/strict 
parse mode(by default let it be lenient mode). It looks not really good to hide 
information about invalid JSON.

Original comment by mst...@gmail.com on 12 Apr 2012 at 5:51