0

I have 3 endpoints which look exactly the same. On one of them I get this exception

    "message": "JSON parse error: Unrecognized token 'Reset': was expecting ('true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Reset': was expecting ('true', 'false' or 'null')\n at [Source: (PushbackInputStream); line: 1, column: 7]"

The DTO I am using for the request has this structure

@Data
public class ValidateResetPasswordReqDto {

    @ApiModelProperty(required = true, allowEmptyValue = false, example = "336068069", value = "Social id")
    private String socialId;

    @ApiModelProperty(required = true, allowEmptyValue = false, example = "0589876541", value = "Phone")
    private String phone;

    @ApiModelProperty(required = true, allowEmptyValue = false, example = "902679", value = "Reset password code")
    private String resetPasswordCode;
} 

I get the exception in this piece of code

@SneakyThrows
    public <T> ResponseEntity<T> postToExtServices(Object dto,
                                                   String url,
                                                   Map<String, String> additionalHeaders,
                                                   ParameterizedTypeReference<T> responseType) {
        String jsonBody = objectMapper.writeValueAsString(dto);
        HttpHeaders headers = httpHeadersService.getDefaultHttpHeaders();
        additionalHeaders.forEach(headers::set);
        HttpEntity<String> request = new HttpEntity<>(jsonBody, headers);

        return restTemplate.exchange(
                getResourceUrl() + url,
                HttpMethod.POST,
                request,
                responseType
        );
    }

When I debug I can clearly see that the String jsonBody is getting populated with the dto and cant figure out what is the issue here

This is the body of the request I am sending from Postman

{
  "socialId": 222855157,    
  "phone": "052-3414725",
  "resetPasswordCode": "3333"
}
Georgi Michev
  • 764
  • 5
  • 18
  • 37
  • 1
    can you show the request you sent? – Jens Jan 08 '20 at 09:09
  • 1
    May be this can help you to debug the issue. https://stackoverflow.com/questions/28604363/jsonparseexception-unrecognized-token-http-was-expecting-true-false-or – P3arl Jan 08 '20 at 09:10
  • @Jens I included the request from Postman – Georgi Michev Jan 08 '20 at 09:13
  • 1
    I think that is not what is send by resttemplate *Unrecognized token 'Reset': was expecting* – Jens Jan 08 '20 at 09:14
  • Yep, many questions ... why you use `ValidateResetPasswordReqDto` with Swagger annotations when your `postToExtServices` does not use it; which are other parameters om method call; when you see this exception - on sending request or getting response. And I'm agree, this exception is not suitable for this json from Postman. – Dmitry Ionash Jan 08 '20 at 09:38

0 Answers0