[MAGNOLIA-5627] Node2Bean: support enums case-insensitively Created: 15/Jan/14  Updated: 11/Aug/16  Resolved: 17/Jan/14

Status: Closed
Project: Magnolia
Component/s: content2bean, core
Affects Version/s: None
Fix Version/s: 5.2.2

Type: Improvement Priority: Neutral
Reporter: Magnolia International Assignee: Magnolia International
Resolution: Fixed Votes: 0
Labels: maintenance
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File 0001-WIP-___-case-insensitive-enums.patch    
Issue Links:
Relates
relates to MAGNOLIA-2734 Provide enum support in content2bean Closed
relates to MAGNOLIA-5887 Node2Bean should not try to instantia... Closed
dependency
is depended upon by MGNLUI-2841 Let filteringMode be configured on Se... Closed
supersession
is superseded by MAGNOLIA-6747 Export EnumCaseInsensitive from node2... Closed
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Testcase included:
Yes
Release notes required:
Yes

 Description   

With MAGNOLIA-2734 (Magnolia 4.1) we introduced support for enums in Content2Bean.

There seems to be some debate as to wether enum consts should be declared in ALL_UPPERCASE (which follows Java coding conventions) or in camelCase (which imo is often more readable, elegant, and doesn't seem as odd when the enum actually as methods and/or implements an interface)

There is however hardly any debate as to whether the ALL_UPPERCASE ones look ugly in configuration trees. (it seems more natural to configure them "like" other properties are configured, especially when next to String properties). And in the case of enums not under our control (i.e when configuring a 3rd party object), having mixed cases makes the tree even more "ugly".

To avoid the debate altogether, I propose that we implement a case-insensitive converter for Enums in Node2Bean. Here's a patch with tests (as well as some commented out tests of alternative implementations which turned out to be significantly slower)

I'd like to introduce this with 5.3. One of the concrete use-case I see is for auto-complete in select fields of 5.x : info.magnolia.ui.form.field.definition.SelectFieldDefinition has a filteringMode property which can be used just for that, but is currently using an int for it's various values. It would benefit from using the enum name, but this enum is a Vaadin class - we can't enforce how they decide to name their consts

As far as I can tell, this could even be included in a patch release, as it should have no side-effect. In the unlikely case that an enum has several consts with the same-name-except-case (MyEnum.foo, MyEnum.FOO), this patch favors exact-case first, anyway.


Generated at Mon Feb 12 04:06:53 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.