Reputation: 47
After alot of research i knew that JAVA does that internally. Tried to replace the slashes with empty string .Also tried to use some libraries to parse String to JSONObject But Same result, A slash before every double qoute..
Request To POSTMAN:
{
"MTI": "0100",
"2": "4655206331051889",
"3": "000000",
"4": "000000012300",
"7": "0321054133",
"11": "001205",
"14": "0325",
"18": "5399",
"22": "022",
"25": "00",
"35": "2312312332",
"37": "206305000014",
"41": "29110001",
"42": "1001001",
"49": "840",
"transactionid": "12",
"co-ordinates": "3042304,293572945"
}
Code:
StringBuilder transactionReq = new StringBuilder();
for (Object o : responseMessage.getChildren().keySet()) {
int key = (Integer) o;
// The Transaction Request Body that has been Received in JSON Format.
transactionReq
.append('"')
.append(key)
.append('"')
.append(" : ")
.append('"')
.append(responseMessage.getValue(key))
.append('"')
.append(" ,");
}
transactionReq
.insert(0, "{")
.deleteCharAt(transactionReq.length() - 1)
.deleteCharAt(transactionReq.length() - 1)
.insert(transactionReq.length(), "}");
response.setMessage(transactionReq.toString().replaceAll("\\\\", ""));
System.out.println(transactionReq.toString());
Console:
{
"message": "{"0" : "0110" ,"1" : "4655206331051889" ,"3" : "000000" ,"4" : "000000012300" ,"6" : "000000000012" ,"7" : "0321054133" ,"11" : "001205" ,"14" : "0325" ,"18" : "5399" ,"22" : "022" ,"25" : "00" ,"35" : "2312312332" ,"37" : "549684 " ,"38" : "84738 " ,"39" : "00" ,"41" : "29110001" ,"42" : "1001001 " ,"49" : "840" ,"57" : "3042304" ,"58" : "293572945"}"
}
Response From POSTMAN:
{
"message": "{\"0\" : \"0110\" ,\"2\" : \"4655206331051889\" ,\"3\" : \"000000\" ,\"4\" : \"000000012300\" ,\"6\" : \"000000000012\" ,\"7\" : \"0321054133\" ,\"11\" : \"001205\" ,\"14\" : \"0325\" ,\"18\" : \"5399\" ,\"22\" : \"022\" ,\"25\" : \"00\" ,\"35\" : \"2312312332\" ,\"37\" : \"549684 \" ,\"38\" : \"84738 \" ,\"39\" : \"00\" ,\"41\" : \"29110001\" ,\"42\" : \"1001001 \" ,\"49\" : \"840\" ,\"57\" : \"3042304\" ,\"58\" : \"293572945\"}"
}
The Output in the console proves that iam sending a right json request.. But the response the shows in postman says the opposite.. Happy to hear any Explanation... Thanks in Advance
Upvotes: 0
Views: 1015
Reputation: 47
It`s built in java, Java treats Strings that way , So i used a DTO To avoid that
Upvotes: 1