I am a little confused as to why my Spring service is not returning any content. I tried mvn clean install
and I also see that the response POJO at the return statement line has actual data when I hit the breakpoint in debugger mode/print to console. Does anyone know what could be the cause?
My @RestController
@Override
public MyServiceResponse getDesiredData(MyRequest myRequest)
throws IOException {
var resp = new MyServiceResponse();
var req = new ServiceRequest<MyRequest>();
req.setPayload(myRequest);
// this update the pass by reference resp object
myRequestProcessor.process(req, resp);
return resp; //at this breakpoint I see data in the debugging console
}
POJO:
@SuperBuilder
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyServiceResponse {
SessionInfo sessionInfo;
}
@SuperBuilder
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class SessionInfo {
Parameters parameters;
}
@SuperBuilder
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Parameters {
@JsonProperty("zip")
String zip;
@JsonProperty("city")
String city;
@JsonProperty("state")
String state;
@JsonProperty("storeNum")
Integer storeNum;
@JsonProperty("startHrs")
String startHrs;
@JsonProperty("endHrs")
String endHrs;
}
It turns out that in my specific case there is another class in the service package that implements the following:
@Pointcut(value = "execution(public * *(..))")
public void publicMethod() {
}
/**
* @see https://docs.spring.io/spring-framework/docs/5.2.9.RELEASE/spring-framework-reference/core.html#aop-pointcuts-combining
*/
@Pointcut(value = "within(com.example.api.service.MyServiceControllerImpl)")
public void forServiceClass() {
}
@Around("publicMethod() && forServiceClass()")
public Object processorLogging(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { ... }
Due to this, the processorLogging is called before and after the API method is called in ControllerImpl. Inside this method the logic did not support a new POJO as the response object so I needed to add that support. Since this is implied behavior, I would verify that there are no additional logic executed past the return of the response in the controller method.