DMN - matching a Java enum by a FEEL expression

673 Views Asked by At

I have a Java enum as an input in a DMN decision table. The DMN call is embedded directly in the Java app. So take some enum:

public enum Foo {
    ONE, TWO
}

I pass an instance of this enum as an input - dmnContext.set("Foo", foo);

I hoped to be able to set a decision table input for foo of type string, and have a rule that matched "ONE". However, this doesn't work, because there is no POJO-String conversion. In the Java code, I could store foo as a String and validate it against the enumerated values (i.e. check foo is in the set ["ONE", "TWO"]), but this will complicate other parts of the application.

How can I achieve this while still using an enum type?

1

There are 1 best solutions below

0
On

Please refer to this existing JIRA record comment section, for the explanation about:

  • why you are experiencing that behaviour
  • and why you should convert your Java-enum to the expected DMN type (which I guess) is a FEEL:string , and not an enum

You can use Jackson to achieve this, instead of resorting to custom code or DMN model modification.

Don't hesitate to Subscribe to the JIRA linked above, as we're hoping of making that work out-of-the-box; but is not trivial since the DMN RTF is thinking about introducing Enumerations directly in DMN eventually, so we need to take into account today what might happen tomorrow.

Since you are linking to Red Hat Product documentation, a reminder that you are strongly encouraged to open a Customer Portal ticket at https://access.redhat.com/support/cases/#/ if you have a Subscription.

I will appreciate your feedback following there references/pointers and I hope those helps