Is there anyway to cast enum to byte array? I am currently using Hbase and in HBase everything should be converted to byte array in order to be persisted so I need to cast an enum value to byte array :)
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You could create a simple utility class to convert the enum's name to bytes:
This is similar to your approach, but even cleaner (and a bit more typesafe, because it is only for enums).
If you have less than 256 enum values you could use the ordinal or a code.
BTW This uses a 1 byte array and creates no garbage in the process.
Well I solved my problem by using
name()
method. For example :