简体   繁体   中英

Saving Java enums in OrientDB

I'm using OrientDB and I would like to save an enum in a field. Something like:

db.save(new ODocument("Car").field("color", Colors.BLUE));

This is the error I'm getting:

Exception in thread "main" com.orientechnologies.orient.core.exception.OSerializationException: Cannot serialize the object since it's not implements the OSerializableStream interface

The easy way to solve this would be to make the "color" property a String and then save it like Colors.BLUE.name() but if that was the case then I'm pretty sure there should be some way for Orient to handle this for me or, even better, some kind of OType that handles this in a more efficient way.

Does anyone know what's the better approach to working with enums?

为该类型注册一个自定义序列化程序 - 看起来你需要为它创建一个OObjectSerializer,并使用OObjectSerializerContext注册它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM