-
Notifications
You must be signed in to change notification settings - Fork 592
unipart body is wrapped with outer string quotes. #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think this is just an artifact of your debugger. This test shows it not to be the case: |
Can you try changing to this please: Object body = "{\"body\": \"sample\"}";
RequestBodyEntity request = Unirest.post(MockServer.POST)
.basicAuth("foo", "bar")
.header("Content-Type", "application/json")
.queryString("foo", "bar")
.body(body); I think the issue is when the body type is Object. |
Ok, so in that case it's using the objectmapper to serialize the string. So when you pass the object mapper a string, it doesn't know that the object is in fact json, so it formats it as an escaped JSON String Is there a reason you are declaring the body as just Object when it's a string? |
The reason I've got Object type is because I have a method for generating request objects with passing in multiple types of body values. I'm happy to update my implementation if you feel it's not worth fixing this. |
Well, "fixing" isn't the right term, you are asking a JSON object mapper to turn a string into a JSON string, and it is doing that. So if we change that, then that is a change in behavior. It might still be the right thing to do, because I'm willing to bet more people use the method by mistake than actually want a string to be a json string. But it's still a breaking change (just a small one) I'll most likely make the change. |
… as a string rather than passing to the object mapper.
this is complete. It also re-routes Unirest's native JSON types from the body(object) method (JsonNode & JSONElement done in 3.9.00 |
Thanks for the quick response on this. |
Describe the bug
When the request body is a json string, then when getting request body, it is wrapped around additional string quotes.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
request.getBody().get().uniPart().getValue().toString()
should return"{\"body\": \"sample\"}"
but returns""{\"body\": \"sample\"}""
instead.Screenshots

If applicable, add screenshots to help explain your problem.
Environmental Data:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: