NotSerializableException 尝试使用 JsonCredentials 从 Apache Beam 查询 BigTable

NotSerializableException trying to use JsonCredentials to query BigTable from Apache Beam

我正在尝试使用以下方式连接到 Google BigTable:

 BigtableOptions.Builder bigTableOptions = new BigtableOptions.Builder()
            .setProjectId(options.getProjectId())
            .setInstanceId(options.getInstanceId())
            .setCredentialOptions(
                    CredentialOptions.jsonCredentials(
                                    new FileInputStream(systemResource.toFile())
                    ));

但是,我得到:

Caused by: java.io.NotSerializableException: java.io.FileInputStream
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)

我试过 2.1.0-快照 和 2.0.0.

还有其他人遇到过这个问题吗?

谢谢。

我最终这样做了:

// Load the keyfile
final String keyFile = "service-account-keyfile.json"
final Path path = Paths.get(ClassLoader.getSystemResource(keyFile).getPath());
// Load and Convert key to a CredentialOptions object
final GoogleCredentials credentials = GoogleCredentials.fromStream(Files.newInputStream(path))
                .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
final CredentialOptions bigTableCredentials = CredentialOptions.credential(credentials);

//Use the credentials
final BigtableOptions bigtableOptions =
            new BigtableOptions.Builder()
                    .setCredentialOptions(bigTableCredentials)