0

my pojo public class VerifyLoginRespDto {

private String access_token;//NOSONAR
private String refresh_token;//NOSONAR
private String edit_by_user;//NOSONAR
private String scope;//NOSONAR
private String token_type;//NOSONAR
private String expires_in;//NOSONAR

}

the controller file

@RequestMapping(value = "/login", method = RequestMethod.POST)
VerifyLoginRespDto verifyLogin(@RequestBody @Valid VerifyLoginDto verifyLogin) {
    // some code
}

but my response have camel key like this

{
    "scope": "basic,",
    "refreshToken": "c2a4f22b-6446-49ad-8cc9-ef1a844d6cbb",
    "tokenType": "bearer",
    "expiresIn": "2591892",
    "accessToken": "54b3f27b-ad5c-4d7b-ae5d-07f56f5f2f42",
    "editByUser": "0"
}

why the key access_token change to accessToken in Spring boot?

kunpengku
  • 117
  • 9
  • Beause I user Jackson , It will output json by the getter method .And my method nama is getAccessToken, so When I use the gson , the wrong goes away。 – kunpengku Apr 04 '18 at 09:46

1 Answers1

1

Because the class you are using for POST request is VerifyLoginDto and the response type of this POST request is VerifyLoginRespDto.

The VerifyLoginRespDto must have property accessToken which is mapped to access_token.

NOTE : Please DON'T USE property name like this private String access_token;. You should follow camel case , because java and Spring follow this very sensitively. All the bean will be created according to camel case only.

Mehraj Malik
  • 14,872
  • 15
  • 58
  • 85