如何编组?以及 protostream 4.4.3java8 中的 ZonedDateTime

问题描述 投票:0回答:1

我有

class P{
@ProtoField(number=1, CollectionImplementation=ArrayList.class)
 List<? extends Account> accounts;
@ProtoField(number=2)
ZonedDateTime fromDate;
@ProtoFactory
P(List<? extends Account> accounts, ZonedDateTime fromDate) {
this.accounts=accounts;
this.fromDate=fromDate;
}

}

Proto 模式构建器为

@AutoProtoBuilder(
basePackages="com.domain",
schemaFileName="abc.proto",
schemaFilePath="proto/",
schemaPackageName="pkg_abc")
Public interface ProtoInitializer extends GeneratedSchema {
}

账户可以

SavingAccount extends Account{
name_sa;
}
ChequingAccount extends Account{
holder_ca;
}

在建设的同时 Org.infinispan.protostream.annotations.ProtoSchemaBuilderExveption:类 java .time.ZonedDateTime 必须可以使用可访问的无参构造函数来实例化

和 java.lang.IllegalStateException:意外的类型种类:WILDCARD

如何为这些生成架构

java-8 infinispan protobuf-java
1个回答
0
投票

以下适配器应该可以工作:

@ProtoAdapter(ZonedDateTime.class)
public final class ZonedDateTimeAdapter {

   @ProtoFactory
   ZonedDateTime create(long epochSecond, String zoneId) {
      return ZonedDateTime.ofInstant(Instant.ofEpochSecond(epochSecond), ZoneId.of(zoneId));
   }

   @ProtoField(number = 1, type = Type.UINT64)
   long getEpochSecond(ZonedDateTime zdt) {
      return zdt.toEpochSecond();
   }

   @ProtoField(number = 2, type = Type.STRING)
   String getZoneId(ZonedDateTime zdt) {
      return zdt.getZone().getId();
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.