I'm working on a Spring Boot application where I am sending SuspendResumeRequest to a REST endpoint and map it to a Java object. However, when the request lands in the controller, all the fields in my object are coming as null. I'm not sure what I'm doing wrong here.I saw all the answers everything but not getting what's wrong in this ?
my sending code :
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<SuspendResumeRequest> request = new HttpEntity<>(suspendResumeRequestMsg, headers);
String apiUrl = ".....;
log.trace("Request sent to prvsite: " + request);
responseEntity = restTemplate.postForEntity(apiUrl, request, SuspendResumeResponse.class);
Log before sending request : Request sent to prvsite: <SuspendResumeRequest(san=DSS30211473, reasonCd=I57, esn=1000035990, type=suspend, protocolId=null, newEsn=null, caseId=null, allowSwap=null, transactionId=EH15874174, transactionDateTime=2025-02-15T06:03:30.646Z),[Content-Type:"application/json"]>
Receiving Controller method :
public ResponseEntity<SuspendResumeResponse> suspendResumeSiteOperation(@RequestBody SuspendResumeRequest suspendResumeRequest) throws Exception, JsonProcessingException {
String method = "suspendResumeSiteOperation()";
log.trace(method + "start controller" + suspendResumeRequest);
}
log : suspendResumeSiteOperation()start controllerSuspendResumeRequest(san=null, reasonCd=null, esn=null, type=null, protocolId=null, newEsn=null, caseId=null, allowSwap=null, transactionId=EH68151313, transactionDateTime=2025-02-15T06:47:24.353Z)
class :
package com.localproject.springboot_sample.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class SuspendResumeRequest {
@JsonProperty("san")
private String san;
@JsonProperty("reasonCd")
private String reasonCd;
@JsonProperty("esn")
private String esn;
@JsonProperty("type")
private String type;
@JsonProperty("protocolId")
private String protocolId;
@JsonProperty("newEsn")
private String newEsn;
@JsonProperty("caseId")
private String caseId;
@JsonProperty("allowSwap")
private String allowSwap;
@JsonProperty("transactionId")
private String transactionId;
@JsonProperty("transactionDateTime")
private String transactionDateTime;
public String getSan() {
return san;
}
public void setSan(String san) {
this.san = san;
}
public String getReasonCd() {
return reasonCd;
}
public void setReasonCd(String reasonCd) {
this.reasonCd = reasonCd;
}
public String getEsn() {
return esn;
}
public void setEsn(String esn) {
this.esn = esn;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getProtocolId() {
return protocolId;
}
public void setProtocolId(String protocolId) {
this.protocolId = protocolId;
}
public String getNewEsn() {
return newEsn;
}
public void setNewEsn(String newEsn) {
this.newEsn = newEsn;
}
public String getCaseId() {
return caseId;
}
public void setCaseId(String caseId) {
this.caseId = caseId;
}
public String getAllowSwap() {
return allowSwap;
}
public void setAllowSwap(String allowSwap) {
this.allowSwap = allowSwap;
}
public String getTransactionId() {
return transactionId;
}
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}
public String getTransactionDateTime() {
return transactionDateTime;
}
public void setTransactionDateTime(String transactionDateTime) {
this.transactionDateTime = transactionDateTime;
}
}