Skip to content

Commit 20be816

Browse files
authored
Fix missing json property name to deserialize issue channel token response correctly (#337)
1 parent d193db4 commit 20be816

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

line-bot-api-client/src/test/java/com/linecorp/bot/client/LineOAuthClientTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public class LineOAuthClientTest {
4444
}
4545

4646
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
47+
private static final String ISSUE_TOKEN_RESPONSE_JSON =
48+
"{\"access_token\":\"accessToken\",\"expires_in\":30,\"token_type\":\"Bearer\"}";
49+
private static final IssueChannelAccessTokenResponse ISSUE_TOKEN_RESPONSE =
50+
IssueChannelAccessTokenResponse.builder()
51+
.expiresInSecs(30)
52+
.accessToken("accessToken")
53+
.build();
4754

4855
private MockWebServer mockWebServer;
4956
private LineOAuthClient target;
@@ -64,15 +71,10 @@ public void tearDown() throws Exception {
6471

6572
@Test
6673
public void issueToken() throws Exception {
67-
final IssueChannelAccessTokenResponse mockResponse =
68-
IssueChannelAccessTokenResponse.builder()
69-
.expiresInSecs(30)
70-
.accessToken("accessToken")
71-
.build();
7274

7375
mockWebServer.enqueue(new MockResponse()
7476
.setResponseCode(200)
75-
.setBody(OBJECT_MAPPER.writeValueAsString(mockResponse)));
77+
.setBody(ISSUE_TOKEN_RESPONSE_JSON));
7678

7779
// Do
7880
final IssueChannelAccessTokenResponse actualResponse =
@@ -88,7 +90,7 @@ public void issueToken() throws Exception {
8890
.isEqualTo("/v2/oauth/accessToken");
8991
assertThat(recordedRequest.getBody().readUtf8())
9092
.isEqualTo("grant_type=client_credentials&client_id=clientId&client_secret=clientSecret");
91-
assertThat(actualResponse).isEqualTo(mockResponse);
93+
assertThat(actualResponse).isEqualTo(ISSUE_TOKEN_RESPONSE);
9294
}
9395

9496
@Test

line-bot-model/src/main/java/com/linecorp/bot/model/oauth/IssueChannelAccessTokenResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.linecorp.bot.model.oauth;
1818

19+
import com.fasterxml.jackson.annotation.JsonProperty;
1920
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2021
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
2122

@@ -31,17 +32,20 @@ public class IssueChannelAccessTokenResponse {
3132
/**
3233
* A short-lived channel access token. Valid for 30 days. Note: Channel access tokens cannot be refreshed.
3334
*/
35+
@JsonProperty("access_token")
3436
String accessToken;
3537

3638
/**
3739
* Time until channel access token expires in seconds from time the token is issued.
3840
*/
41+
@JsonProperty("expires_in")
3942
int expiresInSecs;
4043

4144
/**
4245
* A token type.
4346
*/
4447
@Builder.Default
48+
@JsonProperty("token_type")
4549
String tokenType = "Bearer";
4650

4751
@JsonPOJOBuilder(withPrefix = "")

0 commit comments

Comments
 (0)