Java Function Error

151 views
Skip to first unread message

Ravi Mangalagiri

unread,
Dec 28, 2021, 1:59:38 PM12/28/21
to Kogito development mailing list
Hi Kogito Team,
Merry Christmas and A very happy new year to you all!

Getting the following error when I call a java function in my sample DMN. Please find the project attached.

Log Error : Error invoking function getAge( student ): Unable to coerce parameter: 'student : Any'. Expected class org.dmn.model.Student but found class java.util.HashMap 
Response Message: "message": "Error invoking function getAge( student ): Unable to coerce parameter: 'student : Any'. Expected class org.dmn.model.Student but found class java.util.HashMap",
"messageType": "FEEL_EVALUATION_ERROR", "sourceId": null, "level": "ERROR"

Screen Shot 2021-12-28 at 1.46.48 PM.png
Screen Shot 2021-12-28 at 1.46.21 PM.png




demo.zip

Matteo Mortari

unread,
Dec 28, 2021, 5:36:28 PM12/28/21
to Kogito development mailing list
Hi Ravi,
the DMN model ItemDefinition(s) has no relationship with corresponding Java Types, beyond the information you are carrying over as structural typing when creating the ItemDefinition itself. This means from a DMN specification point of view the engine has no way to know your ItemDefinition named "Student" must correspond to org.dmn.model.Student in the JVM or the likes.

In turn, when using the Drools DMN Engine via the Kogito API, this error is expected, as by the DMN spec we have no way to conform to org.dmn.model.Student specified by your called Java method in BKM, by using only the ItemDefinition definition in the model.

To be fully precise, I believe the use-case might work as-is only when using the Drools DMN Engine in embedded mode and with its API directly, but is more of an edge-case which I wouldn't recommend anyway.

The most appropriate solution would be to adopt the same structural typing also on the Java side, eg: the method should be getAge(java.util.Map) and that should work.
Then, per your definition, you expect the incoming parameter to have a "dob" property (the Map's key).
This approach is aligned with the requirements set forward by Table 47 in the DMN Specification when bridging Java invocation from a DMN model.

Alternatively, you might consider a more generic signature such as getAge(java.lang.Object) for your method, and use Jackson internally in your method or another binding framework to convert the structural type into your java nominal type (your class).
That way, you would get the binding from the structural typing where the property "dob" is defined, to the Java getter "getDateOfBirth()" of the nominal type defined by org.dmn.model.Student in this case.

Hope this clarifies,
MM

--
You received this message because you are subscribed to the Google Groups "Kogito development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kogito-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kogito-development/CALg%3DC8MB28oyLJocwTA%2BdkRbo6xALGygRhCv5KUKvziz4DUEuA%40mail.gmail.com.


--

Ravi Mangalagiri

unread,
Dec 29, 2021, 12:07:18 PM12/29/21
to Kogito development mailing list
This makes sense. Thanks Matteo!

so I update the dmn business knowledge function to take in a hashmap
Screen Shot 2021-12-29 at 12.02.47 PM.png
and changed the arguments in my static utility function to take in HashMap as follows.
Screen Shot 2021-12-29 at 12.06.05 PM.png

Thanks
Ravi Mangalagiri



--
Ravi Mangalagiri
703-505-4240 (c)

Ravi Mangalagiri

unread,
Dec 29, 2021, 4:02:32 PM12/29/21
to Kogito development mailing list
One observation is that there is no clear indication in the DMN that the passed 'Student' object to the function is getting converted to a HashMap internally and making the static java call. 



demo.dmn
Reply all
Reply to author
Forward
0 new messages