unic/neba

Support mapping enumerations

olaf-otto opened this issue · 1 comments

Currently, enumerations are not supported by the field mapping. Here, the use case would be something like

@ResourceModel
class MyModel {
  private EnumType field = EnumType.SOME_INITIAL_VALUE; // or null, or Optional<EnumType>, ...
}

Here, dealing with the potential IllegalArgumentException (or the like) thrown when resolving an enumeration is the most difficult design decision:

  • One could view conversion failures to an enum instance as a serious programming issue, and thus raise an exception and let the resource to model adaptation fail
  • One could also argue that the unstable nature of repository content (think impartial replications and a general absence of type safety) is likely to lead to such issue because of (temporary) content issues, in which case there is no decent way for engineers to handle these cases, especially in views.

Here, it is perhaps most consistent to align to the behavior of Sling's ValueMap, which also handles type conversions and the respective failures. The ValueMap always falls back to null for conversion issues (see https://github.com/apache/sling-org-apache-sling-jcr-resource/blob/a263cc313ec24c05cdc79c9a2eb5a9fe3d14240d/src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java#L47). We should do the same.

Done! NEBA now supports single enum instances, enum arrays and collections of enums.