The latest version of GreenDao ( 2.x ) contains functionality that is ideal for your needs. Custom types exist that can easily serve enumerations.
Enum
public enum ShirtSize { XS(1), S(2), M(3), L(4), XL(5), XXL(6); private final int value; ShirtSize(int value) { this.value = value; } public int value() { return value; } }
Converter
public class ShirtSizeConverter implements PropertyConverter<ShirtSize, Integer> { @Override public ShirtSize convertToEntityProperty(Integer databaseValue) { if(databaseValue == null) { return null; } else { for(ShirtSize value : ShirtSize.values()) { if(value.value() == databaseValue) { return value; } } throw new DaoException("Can't convert ShirtSize from database value: " + databaseValue.toString()); } } @Override public Integer convertToDatabaseValue(ShirtSize entityProperty) { if(entityProperty == null) { return null; } else { return entityProperty.value(); } }
}
Declaring an entity field (in the generator)
entity.addIntProperty("ShirtSize").customType( "com.your_package.ShirtSize", "com.your_package.ShirtSizeConverter" );
source share