Issue
I'm using RestTemplate to post a form, the remote server replays correctly when called via postman but return null if invoked by Java My code is:
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<String, String>();
requestBody.add("grant_type", "client_credentials");
requestBody.add("client_secret", "gdfgf-rtrtr-ssxc");
requestBody.add("client_id", "ttt-yyyy");
org.springframework.http.HttpHeaders headers = new org.springframework.http.HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
RestTemplate restTemplate = new RestTemplate();
String fooResourceUrl = "https://xxxxxx/openid-connect/token";
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(requestBody, headers);
ResponseEntity<B2BResponseTokenV2> foo =
restTemplate.exchange(fooResourceUrl, HttpMethod.POST, request, B2BResponseTokenV2.class);
I'm doing a POST call about this code, but nn Postman it is returning the data correctly, and all the fields have data, however, in Java I only see a filled value when making the POST call and it is the "scope" value, I don't understand why the rest of the values are null
Solution
I feel like we miss some information like B2BResponseTokenV2 code and the postman response.
And yet from the fact that 'scope' field does map correctly and from the image you have uploaded, I guess it has to do something with B2BResponseTokenV2 fields mapping.
I see 'scope' is the only variable made from all lowercase characters. Can it be the response use snake-case while your fields are camel-case and therefore not mapping it correctly? :)
Answered By - yotam hadas
Answer Checked By - Katrina (JavaFixing Volunteer)