Skip to content

Add support for property remapping directly in interface #1077

Description

@dmlloyd

It is seemingly common to deprecate, remap, and/or relocate configuration properties. The configuration interface should have some way to do this. The exact mechanism would need to be discussed, and might end up relying on #767 or similar.

Something like this API sketch could work (note that the remapped configuration names are absolute, which might not be good):

public interface FooBarConfig {
    @WithRemapping(MyRemapper.class)
    String helloWorld();
    // ...
}
/*
 * The set of names that are remapped by this mapper.
 * Instead of causing an error when these properties are encountered,
 * a warning will be issued with the name(s) of the property or properties
 * that replace the remapped property.
 */
@RemapNames("foo.bar.hello-universe")
public final class MyRemapper implements ConfigRemapper {
    /**
     * {@return the remapped value for the corresponding property}
     * This method is only called if there is no user-supplied (non-default) value
     * for the remapped property.
     * The supplied context is the initial context for the configuration.
     * Remapped names must never have an entry in the default values configuration source.
     */
    @Override
    public ConfigValue remap(ConfigSourceInterceptorContext context) {
        ConfigValue mapped = context.proceed("foo.bar.hello-universe");
        return mapped == null ? null : mapped.withName("foo.bar.hello-world");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions