Here I'm having a controller which is of postmapping type. I'm taking the request body as String which a nested JSON. When the controller is being called with the String as request body I want to map that String into a POJO. In that POJO I have fields which are to be mapped from that nested json and also a field which takes the actual String request body as is. Kindly help me how do I map a particular field from that nested json string to the POJO.
The request looks like -
{
"Application": {
"DCode": "unsecliverelease",
"PType": "DA",
"AId": "230391106",
"ApNO": "NTFLbjOF9fXI15AF1YiC",
"crd": {
"cate": "lion",
"ProductCode": "lion"
},
"ld": {
"dm": {
"sn": "3",
"RandomNumbers": {
"RandomNumber01": "319",
"RandomNumber02": "731",
"RandomNumber03": "520",
"RandomNumber04": "102",
"RandomNumber05": "678"
},
"Request": {
"Name": "MSE",
"ACount": "1",
"BrandInd": "wert",
"CID": "123456789",
}
}
}
//controller
@PostMapping(
value = "/decision",
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<crdResponse > getDecision(
@RequestBody final @Valid String request) throws JsonProcessingException {
crdResponse response =
crdService.getDec(request);
return ResponseEntity.ok().body(response);
}
//POJO
public class CRequestModel {
@Column(name = "rid")
@Id
private String crdRqsId;
@Column(name = "scode")
private String scode;
@Column(name = "cid")
private Integer cid;
@Column(name = "RequestNumber")
private Integer requestNumber;
@Column(name = "RequestJson")
private String requestJSON;
@Column(name = "CreatedAt")
private Timestamp createdAt;
}
I want to save the whole JSON string into requestJSON field and want to save CID value(from request JSON STRING) into cid field.
Kindly help me with the same. This input JSON String can change so the order in which the CID is there in current JSON String might vary.