public abstract class YamlProcessor extends Object
Requires SnakeYAML 1.18 or higher, as of Spring Framework 5.0.6.
Modifier and Type | Class and Description |
---|---|
static interface |
YamlProcessor.DocumentMatcher
Strategy interface used to test if properties match.
|
static interface |
YamlProcessor.MatchCallback
Callback interface used to process the YAML parsing results.
|
static class |
YamlProcessor.MatchStatus
Status returned from
YamlProcessor.DocumentMatcher.matches(java.util.Properties) . |
static class |
YamlProcessor.ResolutionMethod
Method to use for resolving resources.
|
Constructor and Description |
---|
YamlProcessor() |
Modifier and Type | Method and Description |
---|---|
protected org.yaml.snakeyaml.Yaml |
createYaml()
Create the
Yaml instance to use. |
protected Map<String,Object> |
getFlattenedMap(Map<String,Object> source)
Return a flattened version of the given map, recursively following any nested Map
or Collection values.
|
protected void |
process(YamlProcessor.MatchCallback callback)
Provide an opportunity for subclasses to process the Yaml parsed from the supplied
resources.
|
void |
setDocumentMatchers(YamlProcessor.DocumentMatcher... matchers)
A map of document matchers allowing callers to selectively use only
some of the documents in a YAML resource.
|
void |
setMatchDefault(boolean matchDefault)
Flag indicating that a document for which all the
document matchers abstain will
nevertheless match. |
void |
setResolutionMethod(YamlProcessor.ResolutionMethod resolutionMethod)
Method to use for resolving resources.
|
void |
setResources(Resource... resources)
Set locations of YAML
resources to be loaded. |
void |
setSupportedTypes(Class<?>... supportedTypes)
Set the supported types that can be loaded from YAML documents.
|
public void setDocumentMatchers(YamlProcessor.DocumentMatcher... matchers)
---
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 Appwhen mapped with
setDocumentMatchers(properties -> ("prod".equals(properties.getProperty("environment")) ? MatchStatus.FOUND : MatchStatus.NOT_FOUND));would end up as
environment=prod url=https://foo.bar.com name=My Cool App
public void setMatchDefault(boolean matchDefault)
document matchers
abstain will
nevertheless match. Default is true
.public void setResolutionMethod(YamlProcessor.ResolutionMethod resolutionMethod)
YamlProcessor.ResolutionMethod.OVERRIDE
.public void setResources(Resource... resources)
resources
to be loaded.YamlProcessor.ResolutionMethod
public void setSupportedTypes(Class<?>... supportedTypes)
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, an IllegalStateException
will be thrown when the corresponding YAML node is processed.
supportedTypes
- the supported types, or an empty array to clear the
supported typescreateYaml()
protected void process(YamlProcessor.MatchCallback callback)
matchers
. If a document
matches it is passed into the callback, along with its representation as Properties.
Depending on the setResolutionMethod(ResolutionMethod)
not all of the
documents will be parsed.callback
- a callback to delegate to once matching documents are foundcreateYaml()
protected org.yaml.snakeyaml.Yaml createYaml()
Yaml
instance to use.
The default implementation sets the "allowDuplicateKeys" flag to false
,
enabling built-in duplicate key handling in SnakeYAML 1.18+.
As of Spring Framework 5.1.16, if custom supported types have been configured, the default implementation creates
a Yaml
instance that filters out unsupported types encountered in
YAML documents. If an unsupported type is encountered, an
IllegalStateException
will be thrown when the node is processed.
LoaderOptions.setAllowDuplicateKeys(boolean)
protected final Map<String,Object> getFlattenedMap(Map<String,Object> source)
YamlProcessor.MatchCallback
the result will
contain the same values as the YamlProcessor.MatchCallback
Properties.source
- the source map