Skip to content

Commit fb97b89

Browse files
Fix deserialisation of empty body in HTTP responses (#426)
## What changes are proposed in this pull request? Fix deserialisation of empty body in HTTP responses ## How is this tested? Added unit test. The unit test fails without this fix.
1 parent 3c77bc2 commit fb97b89

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### New Features and Improvements
66

77
### Bug Fixes
8+
* Fix issue deserializing HTTP responses with an empty body ([#426](https://github.com/databricks/databricks-sdk-java/pull/426)).
89

910
### Documentation
1011

databricks-sdk-java/src/main/java/com/databricks/sdk/core/ApiClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ public <T> void deserialize(Response response, T object) throws IOException {
421421
field.setAccessible(false);
422422
}
423423
}
424-
} else if (response.getBody() != null) {
424+
// mapper does support empty JSON "{}", but not empty body ""
425+
} else if (response.getBody() != null && response.getBody().available() != 0) {
425426
mapper.readerForUpdating(object).readValue(response.getBody());
426427
}
427428
}

databricks-sdk-java/src/test/java/com/databricks/sdk/core/ApiClientTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,17 @@ void failIdempotentRequestAfterTooManyRetries() throws IOException {
268268
"Request GET /api/2.0/sql/sessions/ failed after 4 retries");
269269
}
270270

271+
@Test
272+
void testEmptyBody() throws IOException {
273+
MyEndpointResponse response = new MyEndpointResponse();
274+
Request request = getBasicRequest();
275+
Response rawResponse = new Response(request, 200, "OK", Collections.emptyMap(), "");
276+
ApiClient client =
277+
getApiClient(request, Collections.singletonList(new SuccessfulResponse(rawResponse)));
278+
279+
client.deserialize(rawResponse, response);
280+
}
281+
271282
@Test
272283
void retryDatabricksApi12RetriableError() throws IOException {
273284
Request req = getBasicRequest();

0 commit comments

Comments
 (0)