Skip to content

Commit fb6089f

Browse files
authored
Fix refactor to serialize body (#141)
## Changes In #135 there was a refactor to ApiClient's methods by introducing `prepareRequest`. This accidentally removed the serialization of the body. This PR corrects that issue. ## Tests Ran failing integration tests, and they passed.
1 parent 4c6599c commit fb6089f

File tree

1 file changed

+20
-3
lines changed
  • databricks-sdk-java/src/main/java/com/databricks/sdk/core

1 file changed

+20
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,23 @@ public <I, O> O DELETE(String path, I in, Class<O> target, Map<String, String> h
174174
}
175175
}
176176

177-
private <I> Request prepareRequest(
178-
String method, String path, I in, Map<String, String> headers) {
179-
Request req = new Request(method, path);
177+
private boolean hasBody(String method) {
178+
return !method.equals("GET") && !method.equals("DELETE") && !method.equals("HEAD");
179+
}
180+
181+
private <I> Request prepareBaseRequest(String method, String path, I in)
182+
throws JsonProcessingException {
183+
if (in == null || !hasBody(method)) {
184+
return new Request(method, path);
185+
} else {
186+
String body = serialize(in);
187+
return new Request(method, path, body);
188+
}
189+
}
190+
191+
private <I> Request prepareRequest(String method, String path, I in, Map<String, String> headers)
192+
throws JsonProcessingException {
193+
Request req = prepareBaseRequest(method, path, in);
180194
setQuery(req, in);
181195
setHeaders(req, headers);
182196
return req;
@@ -306,6 +320,9 @@ public <T> T deserialize(String body, JavaType target) throws IOException {
306320
}
307321

308322
private String serialize(Object body) throws JsonProcessingException {
323+
if (body == null) {
324+
return null;
325+
}
309326
return mapper.writeValueAsString(body);
310327
}
311328
}

0 commit comments

Comments
 (0)