AiorosXu / google-gson

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

primitive type support #217

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Object d=100.0;
String jsond=gson.toJson(d);
assertEquals("100.0",jsond);
Object db=gson.fromJson(jsond, Object.class);
//gson bug,this should be true, although given a Object.class, but from the 
json string ,it's clear that , the result should be a Double
assertFalse(d.equals(db));

//also
Object b=true;
String jsonb=gson.toJson(b);
assertEquals("true",jsonb);
Object bb=gson.fromJson(jsonb, Object.class);
//gson bug, bb should be a Boolean
assertFalse(b.equals(bb));

Original issue reported on code.google.com by lanxia...@gmail.com on 25 Jun 2010 at 12:02

GoogleCodeExporter commented 9 years ago
To get what you're requesting, you should change the 2nd argument in the call 
to "fromJson()" to the desired type. Although GSON could infer certain types, 
doing so would be inefficient and/or unreliable because the encoded text has 
very little type information.

Original comment by limpbizkit on 28 Aug 2010 at 4:53