AiorosXu / google-gson

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

GsonBuilder.setLenient(false) #372

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The gson JsonParser is final and it's #parse(JsonReader json) does this:
json.setLenient(true); 

In my unit tests I validate the output of my json rest api and I would like to 
have a parser with strict parsing. Creating my own StrictJsonReader also is not 
possible unless I put it in the com.google.gson package.

Maybe you could add a setter or constructor param for lenient or strict parsing?

Original issue reported on code.google.com by franci...@gmail.com on 26 Oct 2011 at 2:11

GoogleCodeExporter commented 9 years ago
Instead of using JsonParser, you can accomplish the same with the latest GSON 
(from SVN) calling this:
   JsonElement element = gson.fromJson(myStrictReader, JsonElement.class);

Original comment by jessewil...@google.com on 27 Oct 2011 at 2:58

GoogleCodeExporter commented 9 years ago
Would there be a way to do this using gson 1.7.1?

Original comment by franci...@gmail.com on 27 Oct 2011 at 6:52

GoogleCodeExporter commented 9 years ago
You can do it on 1.7.1 if you create your own TypeAdapter for GsonElement. 
Reading the source of Streams.java might make this easier.

But seriously, the code in SVN is about to be released as 2.0. Use that.

Original comment by limpbizkit on 27 Oct 2011 at 12:47

GoogleCodeExporter commented 9 years ago
I'm using gson as provided by play! http://www.playframework.org/ so I might 
suggest them to use 2.0 for the next release.
Thanks for the hint.

Original comment by franci...@gmail.com on 27 Oct 2011 at 12:50

GoogleCodeExporter commented 9 years ago
and as far as I know there is no TypeAdapter in gson 1.7.1

Original comment by franci...@gmail.com on 27 Oct 2011 at 1:30

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 24 Nov 2011 at 8:47

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 30 Dec 2011 at 6:24

GoogleCodeExporter commented 9 years ago
I think this is a pretty good idea.

Original comment by limpbizkit on 12 Feb 2012 at 8:43