GSON一个小BUG的解决之道!
2017-10-13 00:00
176 查看
gson会把
key:value
value中的
=
解析成/u003d`测试用例如下:
@Test public void test() throws Exception { DataSourceConfig result = new DataSourceConfig("com.mysql.jdbc.Driver", "password123456", "jdbc:mysql://DEVIP:PORT/DBNAME?characterEncoding=UTF-8", "username123456", "0"); String expected = "{\"driver\":\"com.mysql.jdbc.Driver\",\"password\":\"password123456\",\"url\":\"jdbc:mysql://DEVIP:PORT/DBNAME?characterEncoding=UTF-8\",\"username\":\"username123456\",\"port\":\"0\"}"; String unexpected = "{\"driver\":\"com.mysql.jdbc.Driver\",\"password\":\"password123456\",\"url\":\"jdbc:mysql://DEVIP:PORT/DBNAME?characterEncoding\\u003dUTF-8\",\"username\":\"username123456\",\"port\":\"0\"}"; assertNotEquals(expected, new Gson().toJson(result)); assertEquals(unexpected, new Gson().toJson(result)); }
可以把其中的new Gson换个方式建出来就OK了!
new GsonBuilder().disableHtmlEscaping().create().toJson(result)
相关文章推荐
- 探讨C#.NET下DropDownList的一个有趣的bug及其解决办法
- onethink动态扩展菜单中遇到的一个小bug解决思路
- 关于google的gson-2.3.1.jar,发现一个奇怪的bug
- 解决打印代码的一个Bug
- 又一个悬而未决的bug被解决
- 解决cocos2d-x pvr.ccz格式的图片有时无法读取的一个bug
- 解决打印代码的一个Bug
- 求大佬帮我解决一个bug!
- 记一个疑难bug的解决过程
- 解决Live Writer语法高亮插件的一个Bug
- 转 VS2005程序运行时出现MSVCP80D.dll not found错误解决方法(VS 2005的一个“Bug”)
- VS2013自定义向导工程的一个bug及其解决办法
- 解决了的一个bug
- 两天解决一个bug引起的真实感想
- 解决ArcGIS 9.3 - 10.2.2的一个BUG
- myEclipe的一个bug 缺少引用的包时出现不能生成编译后的class文件的解决办法
- 关于神一样存在的csdn-一个bug的修复时间是以年记?而且目前还没解决!!!
- Catalyst 10.2解决了一个小BUG
- 解决打印代码的一个Bug
- 一个关于 ie 浏览器的 bug 解决过程和思考