如何覆盖 Spring Cloud GCP 中的默认 Spanner 转换器之一

How to override one of the default Spanner converters in Spring Cloud GCP

我使用 spring-cloud-gcp-data-spanner 从 GCP Spanner 获取数据。我的一个表包含 TIMESTAMP 列,其中包含 UTC 日期时间。

Spring Data Cloud Data 已经有一些自定义类型的 some default Spanner converters。我的实体 class 将 TIMESTAMP (com.google.cloud.Timestamp) 列映射到 LocalDateTime。

它使用默认 TIMESTAMP_LOCAL_DATE_TIME_CONVERTER 并根据我的本地时区 (UTC+3) 转换日期时间。我添加了我的自定义转换器并使用 ConverterAwareMappingSpannerEntityProcessor 指定了它,但我的自定义转换器未被使用并出现在转换器列表的末尾 (GenericConversionService#converters)。

public class LocalDateTimeReadConverter implements Converter<com.google.cloud.Timestamp, LocalDateTime> {

  @Nullable
  @Override
  public LocalDateTime convert(com.google.cloud.Timestamp timestamp) {
    return Instant
        .ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos())
        .atZone(ZoneId.of("UTC"))
        .toLocalDateTime();
  }
}
  @Bean
  public SpannerEntityProcessor spannerConverter(SpannerMappingContext mappingContext) {
    return new ConverterAwareMappingSpannerEntityProcessor(mappingContext,
        List.of(new LocalDateTimeWriteConverter()),
        List.of(new LocalDateTimeReadConverter()));
  }

数据库值: 2020-06-18T15:55:09.000Z
实际值: 2020-06-18T18:55:09.000Z
预期值: 2020-06-18T15:55:09.000Z

如何覆盖默认的 Spanner 转换器?

已由 https://github.com/spring-cloud/spring-cloud-gcp/pull/2580 which is a fix made by Dmitry S as they mentioned in their deleted answer 解决。