Skip to content

Transformers

Max edited this page Oct 30, 2023 · 2 revisions

Transformers

Amber utilizes custom type-transformers in order to allow for you to use your own objects inside of your configuration interfaces. In order to create a transformer, all you need to do is make a new class extending the Transformer<T> interface and supply your object.

From there you can just configure what you want to do with the inputted string. An example of this ur for URLs:

object URLTransformer : Transformer<URL>
{
    override fun fromString(value: String): URL
    {
       return URL(value)
    }
}

This allows you to use the code:

    @EntryName("joesWebsite")
    @Intrinsic
    @DefaultString("https://youtube.com")
    fun onJoeWebsite() : URL

which will return the url that is inside of the config.

Clone this wiki locally