Unable to build a JWTClaimsSet with a claim of type OffsetDateTime

Issue #515 wontfix
Jérôme Vanderstichelen created an issue

Hello,

I have a map of claims containing one claim of type OffsetDateTime.

    private val testClaims: Map<String, Any> = mapOf("sub" to "testSub",
                                                     "custom" to OffsetDateTime.now())

When I try to build a JWTClaimsSet on that object, I have the following error:

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.time.LocalDateTime java.time.OffsetDateTime.dateTime accessible: module java.base does not "opens java.time" to unnamed module @6c9f5c0d

Here is the reproducer:

        val payload = JWTClaimsSet.Builder()
                .apply {
                    testClaims.filterValues { it != null }
                            .forEach { claim(it.key, it.value) }
                }
                .build()

From what I can see on the Internet, it is suggested to create a custom TypeConverter to handle the OffsetDateTime. How can I inject this one in the JWTClaimsSet so that it is being used?

Note that I know about the add-opens, but I would like to avoid to use it as it brings potential security issues (ex: we can bypass some methods that would be called through getter/setter) and it can also brings breaking changes undocumented as developpers could change a private variable without documenting it as it’s something private.

Comments (2)

  1. Log in to comment