Skip to content

Commit

Permalink
Adds missing @Creator so Serde knows which constructor to use when de…
Browse files Browse the repository at this point in the history
…serializing
  • Loading branch information
mliberato committed Sep 1, 2023
1 parent 6961342 commit b54d19a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.micronaut.security.token.jwt.endpoints;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.micronaut.core.annotation.Creator;
import io.micronaut.core.annotation.Introspected;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
Expand Down Expand Up @@ -49,6 +50,7 @@ public TokenRefreshRequest() { }
*
* @param refreshToken Refresh token
*/
@Creator
public TokenRefreshRequest(String refreshToken) {
this.grantType = GRANT_TYPE_REFRESH_TOKEN;
this.refreshToken = refreshToken;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.micronaut.security.token.jwt.endpoints

import io.micronaut.serde.ObjectMapper
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
import spock.lang.Specification

@MicronautTest(startApplication = false)
class SerdeSpec extends Specification {

@Inject
ObjectMapper objectMapper

void "TokenRefreshRequest should be Serializable and Deserializable with Serde"() {
given:
String json = "{\"grant_type\":\"refresh_token\",\"refresh_token\":\"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbkBsb2NhbC5jb20iLCJjb250ZW50LWxlbmd0aCI6IjEwNSIsInByb2R1Y3QiOiJwcm9kdWN0IiwibmJmIjoxNjU5MDc4ODcwLCJyb2xlcyI6W10sImlzcyI6InRlc3RhcHBsaWNhdGlvbiIsImhvc3QiOiJsb2NhbGhvc3Q6NTQ3MjUiLCJjb25uZWN0aW9uIjoiY2xvc2UiLCJjb250ZW50LXR5cGUiOiJhcHBsaWNhdGlvblwvanNvbiIsImV4cCI6MTY1OTA4MjQ3MCwiaWF0IjoxNjU5MDc4ODcwfQ.ugdU-pYUgwU44Skd2jmP4x_aNLAVhrIuSYwyW21ngAg\"}"

when:
TokenRefreshRequest tokenRefreshRequest = new TokenRefreshRequest(
"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbkBsb2NhbC5jb20iLCJjb250ZW50LWxlbmd0aCI6IjEwNSIsInByb2R1Y3QiOiJwcm9kdWN0IiwibmJmIjoxNjU5MDc4ODcwLCJyb2xlcyI6W10sImlzcyI6InRlc3RhcHBsaWNhdGlvbiIsImhvc3QiOiJsb2NhbGhvc3Q6NTQ3MjUiLCJjb25uZWN0aW9uIjoiY2xvc2UiLCJjb250ZW50LXR5cGUiOiJhcHBsaWNhdGlvblwvanNvbiIsImV4cCI6MTY1OTA4MjQ3MCwiaWF0IjoxNjU5MDc4ODcwfQ.ugdU-pYUgwU44Skd2jmP4x_aNLAVhrIuSYwyW21ngAg"
)
String result = objectMapper.writeValueAsString(tokenRefreshRequest)

then:
json == result

when:
tokenRefreshRequest = objectMapper.readValue(json, TokenRefreshRequest)

then:
tokenRefreshRequest
tokenRefreshRequest.refreshToken
}
}

0 comments on commit b54d19a

Please sign in to comment.