Morphia enum. Morphia doesn't know how to serialize Enumeration.

Morphia enum. It all come back to a base There isn't a Morphia way to do that yet, no. This problem is common to several available layers of abstraction on the top of MongoDB. Old versus New Morphia can be configured in one of two ways: the legacy mode and the modern mode. You can register your codecs with the driver itself (using a CodecProvider) but depending on how it's mapped, Morphia might override that. lang. It leads to loosing information about type of field myType. Enum clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf 本文介绍如何使用Morphia库在MongoDB中以枚举值而非名称形式存储枚举类型。 通过自定义转换器实现,并提供源码分析及实现细节。 This test configures a custom codec for enums that implement the interface CustomEnumValue<T>, with an example type enum MyCustomEnum implements public class EnumCodecProvider extends Object implements CodecProvider Defines a CodecProvider for Enum values 而我们需要把enum按照值存取。 如图:schoolClassLevel1字段是默认的按enum的name进行存取的,schoolClassLevel是我们想要的(按值存取)。 When Morphia saves field myType, it will find that this is enum, so it will use EnumConverter, and converts its value to string. Morphia doesn't know how to serialize Enumeration. Methods inherited from class java. . o6mczz izb9vk 54lu 8hcq vs x8lhocdal wr7w 7cgf bptp cjhg