I have 2 object :
Object A {
private String ax;
private String bx;
}
Object B {
private A ax;
private String bx;
}
How I parse :
A objA = A
.builder()
.ax(ax_val)
.bx(bx_val)
.build();
B data = B
.builder()
.objA(objA)
.ax(ax_val)
.build();
String requestBody = gson.toJson(data);
Object receiver in rest :
public class Receiver {
private A objA;
private String ax;
private String bx;
}
Rest :
public ResponseEntity<HashMap<String, Object>> getObj (@Validated @RequestBody Receiver inData) throws Exception {
HashMap<String, Object> hResult = new HashMap<>();
hResult = service.getData(inData);
return ResponseEntity.ok(hResult);
}
I already parsed B as json as for requirement to send to API , but the API can’t map the A inside B even if I already matched the name as well. I want to get A.ax value. Any idea how to solve this ? I’m using gson for JSON parser.
Thank you