Java Cassandra 4.x 映射器可以将 Enum 转换为 int 吗?

Can the Java Cassandra 4.x mapper convert an Enum to an int?

我有一个非常简单的枚举

public enum Axis {
  X, Y, Z;
}

我曾经使用 EnumOrdinalCodec 3.x 驱动程序将其保存到数据库中的 int 中。使用 4.x 我得到一个错误

The CQL ks.table: [snip] defined in the entity class: [snip] declares type mappings that are not supported by the codec registry: Field: axis, Entity Type: [snip].Axis, CQL type: INT

我找不到任何可用于告诉驱动程序如何映射枚举的注释。唯一的钩子似乎是 MapperResultProducer,我无法理解也找不到它的例子。

有没有比手动将枚举映射到其序号更好的方法?

此功能已从 Java 驱动程序 4.8 开始恢复 - 有一个 new ExtraTypeCodecs class that contains additional codecs. You'll need to use codec returned by function ExtraTypeCodecs.enumOrdinalsOf(Class)。 (但请参阅那里的评论,最好不要使用它,因为如果您错误地更改枚举,数字可能会更改)