From b54d19a6ce810cfe5c2bc3499747c358f393c24a Mon Sep 17 00:00:00 2001 From: Marcelo Liberato Date: Fri, 1 Sep 2023 02:00:45 -0300 Subject: [PATCH] Adds missing @Creator so Serde knows which constructor to use when deserializing --- .../jwt/endpoints/TokenRefreshRequest.java | 2 ++ .../token/jwt/endpoints/SerdeSpec.groovy | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test-suite-serde/src/test/groovy/io/micronaut/security/token/jwt/endpoints/SerdeSpec.groovy diff --git a/security-jwt/src/main/java/io/micronaut/security/token/jwt/endpoints/TokenRefreshRequest.java b/security-jwt/src/main/java/io/micronaut/security/token/jwt/endpoints/TokenRefreshRequest.java index 123c8f5490..7d6bcc7257 100644 --- a/security-jwt/src/main/java/io/micronaut/security/token/jwt/endpoints/TokenRefreshRequest.java +++ b/security-jwt/src/main/java/io/micronaut/security/token/jwt/endpoints/TokenRefreshRequest.java @@ -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; @@ -49,6 +50,7 @@ public TokenRefreshRequest() { } * * @param refreshToken Refresh token */ + @Creator public TokenRefreshRequest(String refreshToken) { this.grantType = GRANT_TYPE_REFRESH_TOKEN; this.refreshToken = refreshToken; diff --git a/test-suite-serde/src/test/groovy/io/micronaut/security/token/jwt/endpoints/SerdeSpec.groovy b/test-suite-serde/src/test/groovy/io/micronaut/security/token/jwt/endpoints/SerdeSpec.groovy new file mode 100644 index 0000000000..c60a7ddc78 --- /dev/null +++ b/test-suite-serde/src/test/groovy/io/micronaut/security/token/jwt/endpoints/SerdeSpec.groovy @@ -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 + } +}