Property default

When I want the result of an expression to always be exported in json, I generally do this:

component accessors="true"{
    
   property name="amount" type="Numeric" default="#this.calcAmount()#";

   public Numeric function calcAmount() {
        return 1+2+3;
   }

}

The problem is that “amount” in the json is a string (with quotes) instead of a number.
Or is there a way to tell Lucee which methods to always serialize?

Some idea?

Many thanks.

OS: Linux
Lucee Version: 5.4

Ok, i just solve this init() method.

public Totals function init(){
    setAmount( calcAmount() );
    return this;
}

To instantiate the object I was still using CreateObject and init() is not invoked implicitly like with “new”.
I’ll leave the post, maybe it can be useful to others.

2 Likes