类 YamlProcessor
java.lang.Object
cn.taketoday.core.YamlProcessor
Base class for YAML factories.
Requires SnakeYAML 1.18 or higher
- 从以下版本开始:
- 4.0
- 作者:
- Dave Syer, Juergen Hoeller, Sam Brannen, Brian Clozel, TODAY 2021/9/30 23:33
-
嵌套类概要
嵌套类修饰符和类型类说明static interfaceStrategy interface used to test if properties match.static interfaceCallback interface used to process the YAML parsing results.static enumStatus returned fromYamlProcessor.DocumentMatcher.matches(java.util.Properties).static enumMethod to use for resolving resources. -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected org.yaml.snakeyaml.YamlCreate theYamlinstance to use.getFlattenedMap(Map<String, Object> source) Return a flattened version of the given map, recursively following any nested Map or Collection values.protected voidprotected voidprocess(YamlProcessor.MatchCallback callback) Provide an opportunity for subclasses to process the Yaml parsed from the supplied resources.voidsetDocumentMatchers(YamlProcessor.DocumentMatcher... matchers) A map of document matchers allowing callers to selectively use only some of the documents in a YAML resource.voidsetMatchDefault(boolean matchDefault) Flag indicating that a document for which all thedocument matchersabstain will nevertheless match.voidsetResolutionMethod(YamlProcessor.ResolutionMethod resolutionMethod) Method to use for resolving resources.voidsetResources(Resource... resources) Set locations of YAMLresourcesto be loaded.voidsetSupportedTypes(Class<?>... supportedTypes) Set the supported types that can be loaded from YAML documents.
-
构造器详细资料
-
YamlProcessor
public YamlProcessor()
-
-
方法详细资料
-
setDocumentMatchers
A map of document matchers allowing callers to selectively use only some of the documents in a YAML resource. In YAML documents are separated by---lines, and each document is converted to properties before the match is made. E.g.environment: dev url: https://dev.bar.com name: Developer Setup --- environment: prod url:https://foo.bar.com name: My Cool App
when mapped withsetDocumentMatchers(properties -> ("prod".equals(properties.getProperty("environment")) ? MatchStatus.FOUND : MatchStatus.NOT_FOUND));would end up asenvironment=prod url=https://foo.bar.com name=My Cool App
-
setMatchDefault
public void setMatchDefault(boolean matchDefault) Flag indicating that a document for which all thedocument matchersabstain will nevertheless match. Default istrue. -
setResolutionMethod
Method to use for resolving resources. Each resource will be converted to a Map, so this property is used to decide which map entries to keep in the final output from this factory. Default isYamlProcessor.ResolutionMethod.OVERRIDE. -
setResources
Set locations of YAMLresourcesto be loaded. -
setSupportedTypes
Set the supported types that can be loaded from YAML documents.If no supported types are configured, only Java standard classes (as defined in
SafeConstructor) encountered in YAML documents will be supported. If an unsupported type is encountered, anIllegalStateExceptionwill be thrown when the corresponding YAML node is processed.- 参数:
supportedTypes- the supported types, or an empty array to clear the supported types- 另请参阅:
-
process
Provide an opportunity for subclasses to process the Yaml parsed from the supplied resources. Each resource is parsed in turn and the documents inside checked against thematchers. If a document matches it is passed into the callback, along with its representation as Properties. Depending on thesetResolutionMethod(ResolutionMethod)not all of the documents will be parsed.- 参数:
callback- a callback to delegate to once matching documents are found- 另请参阅:
-
createYaml
protected org.yaml.snakeyaml.Yaml createYaml()Create theYamlinstance to use.The default implementation sets the "allowDuplicateKeys" flag to
false, enabling built-in duplicate key handling in SnakeYAML 1.18+.If custom supported types have been configured, the default implementation creates a
Yamlinstance that filters out unsupported types encountered in YAML documents. If an unsupported type is encountered, anIllegalStateExceptionwill be thrown when the node is processed.- 另请参阅:
-
LoaderOptions.setAllowDuplicateKeys(boolean)
-
getFlattenedMap
Return a flattened version of the given map, recursively following any nested Map or Collection values. Entries from the resulting map retain the same order as the source. When called with the Map from aYamlProcessor.MatchCallbackthe result will contain the same values as theYamlProcessor.MatchCallbackProperties.- 参数:
source- the source map- 返回:
- a flattened map
-
merge
-