k2view-academy / K2View-Academy

Other
15 stars 24 forks source link

How to pass null value to LUFunction actor input ? #1066

Closed avvakandr closed 1 month ago

avvakandr commented 1 month ago

Hello, I'd like to call a java function from my BW flow using LuFunction actor. Function that I'm calling has few input parameters and I need to set few of them into null value. When I'm trying to do so using NullValue actor in front - I still see that my LuFunction is getting empty String object (for inputs defined as String type) instead of null:

This is how it is in the flow - for reference only for executionNote input:

image

and this is what I see from debugger:

image

For reference - these are all my input params defined in java function and as I see null is coming only for Object datatype and always initialized into "" or 0 or 'false' for Primitive datatype (like Integer, Boolean, String, Long).

image

Is there any way to make inputs as null for all datatypes?


Best regards, Andrey

natalylic commented 1 month ago

In Broadway null has an implicit conversion to every supported primitive type (String, Long, etc). The NullValue actor assigns the Object with the null value specifically. You should do one of the following:

  1. Define the required input param as Object. Then, if there is no link to this input, it will be "translated" as null. Or you can as well connect the NullValue actor to this input.
  2. Or, Use a MapCreate actor: image
avvakandr commented 1 month ago

Hi Nataly, If I change input param to be an Object - via LuParam - inptut param - set schema

{ "type": "object" }

then I still get empty string in my java function as an input (or you meant to say I have to change it in Java function from String to Object)?

If I use NullValue -> MapCreate -> LuParam as you proposed in option 2 above - then I get my input as "{}" (it loos like it is getting converted to the type I have under java function for this param):

image

and result in debugger:

image

Is there something wrong in how I use MapCreate ? I have just one input as input1 defined as link:

image

Best regards, Andrey

natalylic commented 1 month ago

I meant that you need to define the Java function input as Object.