我在这里添加了一个复制该问题的示例项目。
我的目标是简单地构建一个GoogleAuthorizationCodeRequest estUrl
。有趣的是,在JVM上运行的一组完全“水合”的地图条目在执行本机可执行文件时是空的。
我尝试过为反射注册类,但没有成功。这是一个示例(来自文件反射-config. json
):
[
{
"name": "com.google.api.client.http.GenericUrl"
}
]
有什么想法吗?
我猜这和API传输数据的方式有关:
public class GenericData extends AbstractMap<String, Object>
事实证明,这确实与数据传输的方式有关。
在下面的片段中,您会注意到@Key
注释用于在水合条目集时生成实际的密钥。
public final class Userinfo extends GenericJson {
@Key
private String email;
@Key("family_name")
private String familyName;
...
事实证明,这种方法广泛用于依赖于google-超文本传输协议-client
的库。
我使用静态编程语言,所以我的解决方案是这样做:
@RegisterForReflection(
targets = [
// google-http-client
com.google.api.client.http.HttpHeaders::class,
com.google.api.client.json.rpc2.JsonRpcRequest::class,
com.google.api.client.json.webtoken.JsonWebSignature::class,
com.google.api.client.json.webtoken.JsonWebToken.Header::class,
// google-api-client
com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeRequestUrl::class,
com.google.api.client.googleapis.auth.oauth2.GoogleBrowserClientRequestUrl::class,
com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets::class,
com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.Details::class,
com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload::class,
com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse::class,
com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo::class,
com.google.api.client.googleapis.json.GoogleJsonError.Details::class,
com.google.api.client.googleapis.json.GoogleJsonError.ParameterViolations::class,
com.google.api.client.googleapis.json.GoogleJsonError::class,
com.google.api.client.googleapis.json.GoogleJsonErrorContainer::class,
com.google.api.client.googleapis.mtls.ContextAwareMetadataJson::class,
// google-api-services-oauth2-v2
com.google.api.services.oauth2.model.Userinfo::class,
com.google.api.services.oauth2.model.Tokeninfo::class,
com.google.api.services.oauth2.Oauth2.Tokeninfo::class,
com.google.api.services.oauth2.Oauth2.Userinfo.Get::class,
com.google.api.services.oauth2.Oauth2.Userinfo.V2.Me::class,
com.google.api.services.oauth2.Oauth2.Userinfo.V2.Me.Get::class,
// google-oauth-client
com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl::class,
com.google.api.client.auth.oauth.OAuthCallbackUrl::class,
com.google.api.client.auth.oauth.OAuthCredentialsResponse::class,
com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl::class,
com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl::class,
com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest::class,
com.google.api.client.auth.oauth2.AuthorizationRequestUrl::class,
com.google.api.client.auth.oauth2.PasswordTokenRequest::class,
com.google.api.client.auth.oauth2.RefreshTokenRequest::class,
com.google.api.client.auth.oauth2.TokenErrorResponse::class,
com.google.api.client.auth.oauth2.TokenRequest::class,
com.google.api.client.auth.oauth2.TokenResponse::class,
com.google.api.client.auth.openidconnect.IdToken.Payload::class,
com.google.api.client.auth.openidconnect.IdTokenResponse::class
// @TODO: This must be fixed first
// https://github.com/googleapis/google-oauth-java-client/issues/947
// com.google.api.client.auth.openidconnect.IdTokenVerifier.PublicKeyLoader.JsonWebKeySet::class
// com.google.api.client.auth.openidconnect.IdTokenVerifier.PublicKeyLoader.JsonWebKey::class
]
)
class ReflectionConfig
我希望这能帮助其他人。