Skip to content

Commit 9140754

Browse files
authored
Merge pull request #879 from debychkov/develop
fixed issue with null in legacy driver's json response deserializer + test
2 parents 6092358 + 7714fa8 commit 9140754

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/ClickHouseResponseGsonDeserializer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ private String getAsString(JsonElement value) {
7878
valueStr = value.getAsString();
7979
} else if (value.isJsonArray()) {
8080
valueStr = arrayToString(value);
81+
} else if (value.isJsonNull()){
82+
valueStr = null;
8183
} else {
82-
throw new IllegalArgumentException("unexpected jsonElementType: " + value.toString());
84+
valueStr = value.toString();
8385
}
8486
return valueStr;
8587
}

clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/ClickHouseStatementImplTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,16 @@ public void testJsonResponse() throws SQLException {
549549
}
550550
}
551551

552+
@Test(groups = "integration")
553+
public void testJsonResponseWithNull() throws SQLException {
554+
try (ClickHouseStatement s = connection.createStatement()) {
555+
ClickHouseResponse response = s.executeQueryClickhouseResponse(
556+
"SELECT 1 AS one, 0/0 AS n");
557+
assertNotNull(response);
558+
assertEquals(response.getData(), Collections.singletonList(Arrays.asList("1", null)));
559+
}
560+
}
561+
552562
private static String readQueryId(ClickHouseStatementImpl stmt, long timeoutSecs) {
553563
long start = System.currentTimeMillis();
554564
String value;

0 commit comments

Comments
 (0)