'Gatling:If session exist attribute set the #{attribute} to real value, and if its null set #{attribute} to null, how can I do?

Our API sequence is A->B

1step: extract API A's discountPremuim and set it to session

.check(jsonPath("$[0].discountPremium").optional.saveAs("discountPremium"))

2step: API B’s json feeder use this discountPremuim

{        
    ...
    "discountPremium": #{discountPremium},
    ...
}

But API A may not respond the discountPremuim if goods don't have the discount.

I try use

      .exec(_.set("discountPremium",null.asInstanceOf[Any]))

to set it to null, but Failed to build request: Attribute discountPremium's value is null

here’s what I want

    "discountPremium": #{discountPremium.exist()?discountPremium:null},

I can not find the Gatling EL’s ternary operator on the gatling.io

how can I do? many thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source