EnumerablePropertySource<T extends Object> class abstract

A property source that can list every key it has.

Looking a key up is enough for @Value('${a.b}'), but @ConfigurationProperties binding of maps and lists, relaxed names and config data must find all keys under a prefix, which needs the list. Extend it instead of AbstractPropertySource when your source knows its keys; the framework's map, file and command-line sources all do.

// Key=value lines of a `.env` file, already parsed into a map.
class EnvFileSource extends EnumerablePropertySource<Map<String, String>> {
  EnvFileSource(Map<String, String> values) : super('envFile', values);

  @override
  List<String> get propertyNames => source.keys.toList();

  @override
  Object? getProperty(String name) => source[name];
}

Spring (Java):

class EnvFileSource extends EnumerablePropertySource<Map<String, String>> {
  EnvFileSource(Map<String, String> values) { super("envFile", values); }

  @Override
  public String[] getPropertyNames() {
    return getSource().keySet().toArray(String[]::new);
  }

  @Override
  public Object getProperty(String name) {
    return getSource().get(name);
  }
}
Inheritance
Implementers

Constructors

EnumerablePropertySource(String name, T source)
Creates a source called name that reads from source.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
name → String
The name of this source, unique within the environment's list. It is how other code finds, replaces or orders the source, and it appears in error messages (Config resource 'resources:/application.yml').
finalinherited
propertyNames → List<String>
The keys of all properties this source has, as they are written in it.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
source → T
The object the values are read from: a map, the command-line arguments, a client.
finalinherited

Methods

containsProperty(String name) → bool
Whether propertyNames contains name. Override it with a faster lookup when the source has one.
override
getProperty(String name) → Object?
The value of the property name, or null when this source does not have it (the environment then asks the next source).
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
Whether other is a source with the same name, whatever its values, as in Spring.
inherited