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)