1

To consume a rest service, this is the service response

{
   "message": "200",
   "result": "SUCCESS",
   "Test_Id": "23324"
}

Code to consume the service.

ResponseEntity<InfoDto> result = null;
final String uri ="https://app.ed.im/api";

RestTemplate restTemplate = new RestTemplate();

HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
result = restTemplate.exchange(uri, HttpMethod.GET, entity, InfoDto.class);

This is the dto

public class InfoDto implements Serializable {
    private String message;
    private String result;
    private String Test_Id;
}

Once this is executed

I had received the values of message and result, but Test_Id value is not mapped.

Giorgi Tsiklauri
  • 9,715
  • 8
  • 45
  • 66
user630209
  • 1,123
  • 4
  • 42
  • 93

1 Answers1

2

If there is an issue with parameter name's code convention, add JsonProperty with exact match

@JsonProperty("Test_Id")
private String Test_Id; // prefer rename to testId

There's probably an underscore to camel-case conversion

Giorgi Tsiklauri
  • 9,715
  • 8
  • 45
  • 66
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • My java model objects are auto-generated and I can't change them to @JsonProperty, they are all annotated with @SerializedName(SERIALIZED_NAME. How can I do this? – Devi Apr 06 '23 at 20:59
  • @Devi please ask a new question with more details – Ori Marko Apr 09 '23 at 03:40