You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, Jakarta Config allows for loading config into an interface
@Configuration
public interface A {
String value();
}
The most use-cases, however, are as follows:
if (config.property('NAME1')) {
// do something
}
if (config.property('NAME2')) {
// do something else
}
The convenient way is to allow the possibility to load the single value as Loader.bootstrap().path("NAME1").asString().
In MP config, there is a similar notion: config.getValue("NAME1", String.class)
There are the following possibilities:
Allow just few methods: asInt(), asBoolean, asString
Allow all primitive types: boolean, byte, short, float, double, int, long, char, and String
Allow just asString() and more generic as(Class<T> type) and as(TypeToken type) - this has an advantage that later on the config could support as(UserDefinedType), but a disadvantage that we should define a way to pass convertors to the Loader.
The use-case usually checks whether the property is present. That can be implemented by:
returning null when not available
returning Optional<> (my favourite)
throwing NoSuchObjectException
implement a complementary isProperty()
In the case of Optional, it would be possible to use: loader.path("my.property").asString().ifPresent(myProperty -> doSomething(myProperty))
The text was updated successfully, but these errors were encountered:
Currently, Jakarta Config allows for loading config into an interface
The most use-cases, however, are as follows:
The convenient way is to allow the possibility to load the single value as
Loader.bootstrap().path("NAME1").asString()
.In MP config, there is a similar notion:
config.getValue("NAME1", String.class)
There are the following possibilities:
asInt()
,asBoolean
,asString
asString()
and more genericas(Class<T> type)
andas(TypeToken type)
- this has an advantage that later on the config could supportas(UserDefinedType)
, but a disadvantage that we should define a way to pass convertors to the Loader.The use-case usually checks whether the property is present. That can be implemented by:
null
when not availableOptional<>
(my favourite)NoSuchObjectException
isProperty()
In the case of Optional, it would be possible to use:
loader.path("my.property").asString().ifPresent(myProperty -> doSomething(myProperty))
The text was updated successfully, but these errors were encountered: