My need is based on this library Unirest . I need to make a post request for a% ap_%. Both services are internal and I have access to the code.
I get the information from the front as follows:
{
"id": [
15869550,
15975717
],
"carId": "1",
"date": "2012-02-28T20:27:21+0000"
}
Except the information in a class using PHP
:
public Map<String, Object> getFields() {
Map<String, Object> fields = new HashMap<>();
fields.put("carId", this.audit.getCarId());
fields.put("date", CalendarHelper.format(this.audit.getDate()));
fields.put("id[]", this.audit.getId());
// for (Integer item : this.audit.getId()) {
// fields.put("id[]", item);
// }
return fields;
}
When I am running Map<String, Object>
with post
the http client receives a body
routing and a String
fields. Thus: Map
.
Here's an explanation of the reason for naming the HttpRequestWithBody post(String path, Map<String, Object> fields)
field in id[]
. I can get Map<String, Object>
id's.
This is how the end-point expects to receive the information:
MyproblemisthatthefieldN
endsuphavingtwoid[]
andtheconversiontovalue
ofbody
endsuplikethis:
as shown in the resquest
method. I tried to run a test and applied the getFields()
field to the id[]
loop to see the behavior. And I noticed that for
does not duplicate the key. Just replace the value.
My need is to better understand if the knowledge I am applying is not overly complex. For me it was to be a simple problem. However it is taking more time than expected.
Note: All structures can be modified in order to simplify communication between the parties. What I can not tinker with is the return type of the method that should be of type Map
.
Walking to the simplicity side what can I do?
- Simplify how I get information from the front?
- Simplify how back-java information works?
- Simplify how to step information in form-data?