M06H
M06H

Reputation: 1783

injection of empty set from reading properties

<property name="listOfIds" value="#{'${list.ids}'.trim().split(' *, *')}"/>

I am setting a list of Ids with spring bean and I was wondering if there was a way of initialising my collection Set to be empty with SPEL if no properties were set:

list.ids=

such that when I call...

 if (connection.getListOfIds().isEmpty()) {
    //do something
    }

it returns that the set contains no elements. or Is there an alternative way I can read in empty set from the properties file.

Upvotes: 1

Views: 499

Answers (1)

Anudeep Gade
Anudeep Gade

Reputation: 1395

Basically you can use Elvis operator ?: and return T(java.util.Collections).emptyList()

"#primes?:T(java.util.Collections).emptyList()"

Default values can be provided as ${myProps.item:#{defaultValue}}

Upvotes: 1

Related Questions