discomarathon / google-gson

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

toJson has many useless character #198

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Struts2+hibernate3.3+Spring
SysUserConfig sysUserConfig = 
this.sysUserConfigService.getSysUserConfig(this.sysUserConfig.getId());

out.write(new GsonBuilder().setDateFormat("yyyy-MM-
dd").disableHtmlEscaping().create().toJson(sysUserConfig));

output:
{"handler":{"interfaces":[{}],"constructed":true,"persistentClass":{},"getI
dentifierMethod":{"clazz":{},"slot":27,"name":"getId","returnType":{},"para
meterTypes":[],"exceptionTypes":[],"modifiers":1,"root":{"clazz":{},"slot":
27,"name":"getId","returnType":{},"parameterTypes":[],"exceptionTypes":[],"
modifiers":1,"override":false},"override":false},"setIdentifierMethod":{"cl
azz":{},"slot":0,"name":"setId","returnType":{},"parameterTypes":[{}],"exce
ptionTypes":[],"modifiers":1,"root":{"clazz":{},"slot":0,"name":"setId","re
turnType":{},"parameterTypes":[{}],"exceptionTypes":[],"modifiers":1,"overr
ide":false},"override":false},"overridesEquals":false,"entityName":"com.tjs
oft.vo.SysUserConfig","id":"20100308170143781","target":{"id":"201003081701
43781","configName":"测试","userId":999999999999999,"slStartDate":"2009-01-
01","slEndData":"2010-03-31","createDate":"2010-03-
08","status":"1","bjStartDate":"2009-01-01","bjEndDate":"2010-04-
02","zaiban":"1","banjie":"1","suoyou":"1"},"initialized":true,"unwrap":fal
se}}

but i just want:

{"id":"20100308170143781","configName":"测
试","userId":999999999999999,"slStartDate":"2009-01-01","slEndData":"2010-
03-31","createDate":"2010-03-08","status":"1","bjStartDate":"2009-01-
01","bjEndDate":"2010-04-02","zaiban":"1","banjie":"1","suoyou":"1"}

how can i do it?

Original issue reported on code.google.com by ilovehon...@gmail.com on 19 Mar 2010 at 8:49

GoogleCodeExporter commented 9 years ago
This doesn't look like a defect. Using GsonBuilder, you can specify to only 
serialize
objects which match the @Expose annotation, or you could build a proxy class 
with
only those fields, set them from sysUserConfig, and then serialize that. 

Original comment by arcanef...@gmail.com on 20 Apr 2010 at 5:28

GoogleCodeExporter commented 9 years ago
This doesn't look like a defect. Using GsonBuilder, you can specify to only 
serialize
objects which match the @Expose annotation, or you could build a proxy class 
with
only those fields, set them from sysUserConfig, and then serialize that. 

Original comment by arcanef...@gmail.com on 20 Apr 2010 at 5:28

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 28 Aug 2010 at 5:28