Java Enums in CBL

On Android CBL, can I put/get an Enum in the properties map?
When getting the Enum value from the database, do I simply cast to an Enum?
Also in a View, can I work with the Enum as an Enum and not like a string?

Simple example to better explain my question.
public enum Animal { CAT, DOG, DEER }
If ‘properties’ is the name of the map variable, Can I then do:
Animal myAnimal = Animal.CAT;

  1. properties.put(“aKey”, myAnimal
  2. Animal x = (Animal)properties.get(“aKey”);

And in a View Mapper:
Animal x = (Animal)properties.get(“aKey”);
if (x.equals(Animal.CAT)) emit x;
And of course to use the enum as startKey and/or endKey.


To answer my own question after extensive testing.
It is best to store/put the enum as a string (either via toString() or .name(). Then upon retrieval/get you instantiate the enum with valueOf(String).

1 Like

Check this one to know more about…Java Enum