diff --git a/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/ClickHouseResponseGsonDeserializer.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/ClickHouseResponseGsonDeserializer.java index a7e1e517d..32c8fbe23 100644 --- a/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/ClickHouseResponseGsonDeserializer.java +++ b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/ClickHouseResponseGsonDeserializer.java @@ -78,8 +78,10 @@ private String getAsString(JsonElement value) { valueStr = value.getAsString(); } else if (value.isJsonArray()) { valueStr = arrayToString(value); + } else if (value.isJsonNull()){ + valueStr = null; } else { - throw new IllegalArgumentException("unexpected jsonElementType: " + value.toString()); + valueStr = value.toString(); } return valueStr; } diff --git a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/ClickHouseStatementImplTest.java b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/ClickHouseStatementImplTest.java index a1ddc301b..9bb493d2f 100644 --- a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/ClickHouseStatementImplTest.java +++ b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/ClickHouseStatementImplTest.java @@ -549,6 +549,16 @@ public void testJsonResponse() throws SQLException { } } + @Test(groups = "integration") + public void testJsonResponseWithNull() throws SQLException { + try (ClickHouseStatement s = connection.createStatement()) { + ClickHouseResponse response = s.executeQueryClickhouseResponse( + "SELECT 1 AS one, 0/0 AS n"); + assertNotNull(response); + assertEquals(response.getData(), Collections.singletonList(Arrays.asList("1", null))); + } + } + private static String readQueryId(ClickHouseStatementImpl stmt, long timeoutSecs) { long start = System.currentTimeMillis(); String value;