java - Null response from restTemplate with a swagger generated client

Viewed 17

I have a Swagger and I have used Swagger Editor to generate the Java model which I then imported in my project.

It looks like I'm having trouble only with the endpoints that embed the response in JSON object, for example:

{
    "LockDocFourDTO": {
        "idprotocollo": "22000333333300085093",
        "pdr": null,
        "flag": "N"
    }
}

This is represented by the autogenerated java code:

public class WebapiGetFlagFourLockedResponseObject {
  @SerializedName("LockDocFourDTO")  
  private WebapiGetFlagFourLocked lockDocFourDTO = null;
//...getters and setters and constructor
}

And the internal object:

public class WebapiGetFlagFourLocked {
  @SerializedName("idprotocollo")
  private String idprotocollo = null;

  @SerializedName("pdr")
  private String pdr = null;

  @SerializedName("flag")
  private String flag = null;

//...getters and setters and constructor

}

And then I use one of these instructions to call the rest api:

ResponseEntity<WebapiGetFlagFourLockedResponseObject> lock = newFourRestTemplate.postForEntity(newFourBaseUrl+GET_FLAG_FOUR_LOCKED, body, WebapiGetFlagFourLockedResponseObject.class);
WebapiGetFlagFourLockedResponseObject ob = newFourRestTemplate.postForObject(newFourBaseUrl+GET_FLAG_FOUR_LOCKED, body, WebapiGetFlagFourLockedResponseObject.class);

But then ob.getLockDocFourDTO() is null. What am I doing wrong?

0 Answers
Related