In order to create a multipart/form-data request, I need to transform either a nested POJO or the nested JSON that results from Jackson serialization to a Map<String, String> with the following format.
Map<String, String> map = new HashMap<>();
map.put("transaction_id", request.getTransactionId());
map.put("person[dob]", request.getPerson().getDob());
map.put("person[first_name]", request.getPerson().getFirstName());
map.put("person[last_name]", request.getPerson().getLastName());
Here are the definitions of the relevant classes.
@Getter
public class Request {
@JsonProperty("transaction_id")
private String transactionId;
private Person person;
}
@Getter
public class Person {
@JsonProperty("dob")
private String dob;
@JsonProperty(value = "first_name")
private String firstName;
@JsonProperty(value = "last_name")
private String lastName;
}
Is there someway to do the map population automatically from a given Request POJO or serialized JSON, e.g. using Jackson that I already use for JSON serialization?