クラス PropertyMapper

java.lang.ObjectSE
org.springframework.boot.context.properties.PropertyMapper

public final class PropertyMapper extends ObjectSE
指定されたソースから宛先に値をマップするために使用できるユーティリティ。主に、@ConfigurationProperties からサードパーティのクラスにマッピングするときに役立つことを目的としています。

述語に基づいて値をフィルタリングし、必要に応じて値を適合させることができます。例:

PropertyMapper map = PropertyMapper.get();
map.from(source::getName)
  .to(destination::setName);
map.from(source::getTimeout)
  .when(this::thisYear)
  .asInt(Duration::getSeconds)
  .to(destination::setTimeoutSecs);
map.from(source::isEnabled)
  .whenFalse().
  .toCall(destination::disable);

マッピングは、最終的に setter に適用したり、method call をトリガーしたり、new instance を作成したりできます。

デフォルトでは、null 値とサプライヤーからスローされた NullPointerExceptionSE はフィルタリングされ、コンシューマーには適用されません。NULL 値を適用したい場合は、PropertyMapper.Source.always() を使用してください。

導入:
2.0.0
作成者:
Phillip Webb, Artsiom Yudovin, Chris Bono, Moritz Halbritter