Without custom methods, unfortunately now is a bit cumbersome, but instead you can save the string representation and convert it to / from an enumeration.
public enum Foo { FOO } // V1: Using static methods public class Bar1 extends RealmObject { private String enumValue; // Getters/setters // Static methods to handle the enum values public static Foo getEnum(Bar1 obj) { return Foo.valueOf(obj.getEnumValue()) } public static Foo setEnum(Bar1 obj, Foo enum) { return obj.setEnumValue(enum.toString()); } } // V2: Use a dummy @Ignore field to create getters/setters you can override yourself. public class Bar2 extends RealmObject { private String enumValue; // Dummy field @Ignore private String enum; public void setEnumValue(String enumValue) { this.enumValue = enumValue; } public String getEnumValue() { return enumValue; } public void setEnum(Foo foo) { setEnumValue(foo.toString()); } public Foo getEnum() { return Foo.valueOf(getEnumValue()); } }
source share