Skip to content

Commit 6eff9ed

Browse files
committed
Issue #362 when passing a string to the body method for a post, route as a string rather than passing to the object mapper.
1 parent 3376fcf commit 6eff9ed

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.9.00 (pending)
2+
* Issue #362 when passing a string to the body method for a post, route as a string rather than passing to the object mapper.
3+
4+
15
## 3.8.06
26
* issue #359 make the default object mapper lazy so gson can be excluded
37

unirest/src/main/java/kong/unirest/HttpRequestBody.java

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ public RequestBodyEntity body(String body) {
107107

108108
@Override
109109
public RequestBodyEntity body(Object body) {
110+
if(body instanceof String){
111+
return body((String)body);
112+
}
110113
return body(getObjectMapper().writeValue(body));
111114
}
112115

unirest/src/test/java/BehaviorTests/UniBodyPostingTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,17 @@ void theRequestBodyIsAString() {
176176
Object value = request.getBody().get().uniPart().getValue();
177177
assertEquals("{\"body\": \"sample\"}", value);
178178
}
179+
180+
@Test
181+
void stringPassedToObjectGetsPassedToString() {
182+
Object body = "{\"body\": \"sample\"}";
183+
RequestBodyEntity request = Unirest.post(MockServer.POST)
184+
.basicAuth("foo", "bar")
185+
.header("Content-Type", "application/json")
186+
.queryString("foo", "bar")
187+
.body(body);
188+
189+
Object value = request.getBody().get().uniPart().getValue();
190+
assertEquals("{\"body\": \"sample\"}", value);
191+
}
179192
}

0 commit comments

Comments
 (0)