Top Description Inners Fields Constructors Methods
org.springframework.beans.factory.config

public abstract Class YamlProcessor

extends Object
Class Inheritance
Known Direct Subclasses
org.springframework.beans.factory.config.YamlPropertiesFactoryBean, org.springframework.beans.factory.config.YamlMapFactoryBean
Imports
java.io.IOException, .Reader, java.util.Arrays, .Collection, .Collections, .LinkedHashMap, .List, .Map, .Properties, .Set, java.util.stream.Collectors, org.apache.commons.logging.Log, .LogFactory, org.yaml.snakeyaml.DumperOptions, .LoaderOptions, .Yaml, org.yaml.snakeyaml.composer.ComposerException, org.yaml.snakeyaml.constructor.Constructor, org.yaml.snakeyaml.inspector.TagInspector, org.yaml.snakeyaml.nodes.Tag, org.yaml.snakeyaml.reader.UnicodeReader, org.yaml.snakeyaml.representer.Representer, org.springframework.core.CollectionFactory, org.springframework.core.io.Resource, org.springframework.lang.Nullable, org.springframework.util.Assert, .ObjectUtils, .StringUtils

Base class for YAML factories.

Requires SnakeYAML 2.0 or higher, as of Spring Framework 6.1.

Authors
Dave Syer, Juergen Hoeller, Sam Brannen, Brian Clozel
Since
4.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
YamlProcessor.DocumentMatcher

Strategy interface used to test if properties match.

public static interface
YamlProcessor.MatchCallback

Callback interface used to process the YAML parsing results.

public static enum
public static enum
YamlProcessor.ResolutionMethod

Method to use for resolving resources.

private class

Field Summary

Modifier and TypeField and Description
private List<YamlProcessor.DocumentMatcher>
private final Log
private boolean
private YamlProcessor.ResolutionMethod
private Resource[]
private Set<String>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private Map<String, Object>
asMap(Object object)

private void
protected Yaml
createYaml()

Create the Yaml instance to use.

protected final Map<String, Object>

Returns:

a flattened map
getFlattenedMap
(Map<String, Object>
the source map
source
)

Return a flattened version of the given map, recursively following any nested Map or Collection values.

private void
protected void
process(YamlProcessor.MatchCallback
a callback to delegate to once matching documents are found
callback
)

Provide an opportunity for subclasses to process the Yaml parsed from the supplied resources.

private boolean
process(YamlProcessor.MatchCallback callback, Yaml yaml, Resource resource)

private boolean
public void
setDocumentMatchers(YamlProcessor.DocumentMatcher... matchers)

A map of document matchers allowing callers to selectively use only some of the documents in a YAML resource.

public void
setMatchDefault(boolean matchDefault)

Flag indicating that a document for which all the document matchers abstain will nevertheless match.

public void
setResolutionMethod(YamlProcessor.ResolutionMethod resolutionMethod)

Method to use for resolving resources.

public void
setResources(Resource... resources)

Set locations of YAML resources to be loaded.

public void
setSupportedTypes(Class<?>...
the supported types, or an empty array to clear the supported types
supportedTypes
)

Set the supported types that can be loaded from YAML documents.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

documentMatchersback to summary
private List<YamlProcessor.DocumentMatcher> documentMatchers
loggerback to summary
private final Log logger
matchDefaultback to summary
private boolean matchDefault
resolutionMethodback to summary
private YamlProcessor.ResolutionMethod resolutionMethod
resourcesback to summary
private Resource[] resources
supportedTypesback to summary
private Set<String> supportedTypes

Constructor Detail

YamlProcessorback to summary
public YamlProcessor()

Method Detail

asMapback to summary
private Map<String, Object> asMap(Object object)
Annotations
@SuppressWarnings:rawtypes, unchecked
buildFlattenedMapback to summary
private void buildFlattenedMap(Map<String, Object> result, Map<String, Object> source, String path)
Annotations
@SuppressWarnings:rawtypes, unchecked
createYamlback to summary
protected Yaml createYaml()

Create the Yaml instance to use.

The default implementation sets the "allowDuplicateKeys" flag to false, enabling built-in duplicate key handling.

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, a ComposerException will be thrown when the node is processed.

See Also
LoaderOptions#setAllowDuplicateKeys(boolean)
getFlattenedMapback to summary
protected final Map<String, Object> getFlattenedMap(Map<String, Object> source)

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 a MatchCallback the result will contain the same values as the MatchCallback Properties.

Parameters
source:Map<String, Object>

the source map

Returns:Map<String, Object>

a flattened map

Since
4.1.3
handleProcessErrorback to summary
private void handleProcessError(Resource resource, IOException ex)
processback to summary
protected void process(YamlProcessor.MatchCallback callback)

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 the matchers. If a document matches it is passed into the callback, along with its representation as Properties. Depending on the setResolutionMethod(ResolutionMethod) not all the documents will be parsed.

Parameters
callback:YamlProcessor.MatchCallback

a callback to delegate to once matching documents are found

See Also
createYaml()
processback to summary
private boolean process(YamlProcessor.MatchCallback callback, Yaml yaml, Resource resource)
processback to summary
private boolean process(Map<String, Object> map, YamlProcessor.MatchCallback callback)
setDocumentMatchersback to summary
public void setDocumentMatchers(YamlProcessor.DocumentMatcher... matchers)

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 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
setMatchDefaultback to summary
public void setMatchDefault(boolean matchDefault)

Flag indicating that a document for which all the document matchers abstain will nevertheless match. Default is true.

setResolutionMethodback to summary
public void setResolutionMethod(YamlProcessor.ResolutionMethod resolutionMethod)

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 is ResolutionMethod#OVERRIDE.

setResourcesback to summary
public void setResources(Resource... resources)

Set locations of YAML resources to be loaded.

See Also
ResolutionMethod
setSupportedTypesback to summary
public void setSupportedTypes(Class<?>... supportedTypes)

Set the supported types that can be loaded from YAML documents.

If no supported types are configured, only Java standard classes (as defined in org.yaml.snakeyaml.constructor.SafeConstructor) encountered in YAML documents will be supported. If an unsupported type is encountered, a ComposerException will be thrown when the corresponding YAML node is processed.

Parameters
supportedTypes:Class<?>[]

the supported types, or an empty array to clear the supported types

Since
5.1.16
See Also
createYaml()
org.springframework.beans.factory.config back to summary

public Interface YamlProcessor.DocumentMatcher

Annotations
@FunctionalInterface

Strategy interface used to test if properties match.

Method Summary

Modifier and TypeMethod and Description
public YamlProcessor.MatchStatus

Returns:

the status of the match
matches
(Properties
the properties to test
properties
)

Test if the given properties match.

Method Detail

matchesback to summary
public YamlProcessor.MatchStatus matches(Properties properties)

Test if the given properties match.

Parameters
properties:Properties

the properties to test

Returns:YamlProcessor.MatchStatus

the status of the match

org.springframework.beans.factory.config back to summary

public Interface YamlProcessor.MatchCallback

Annotations
@FunctionalInterface

Callback interface used to process the YAML parsing results.

Method Summary

Modifier and TypeMethod and Description
public void
process(Properties
the properties to process (as a flattened representation with indexed keys in case of a collection or map)
properties
,
Map<String, Object>
the result map (preserving the original value structure in the YAML document)
map
)

Process the given representation of the parsing results.

Method Detail

processback to summary
public void process(Properties properties, Map<String, Object> map)

Process the given representation of the parsing results.

Parameters
properties:Properties

the properties to process (as a flattened representation with indexed keys in case of a collection or map)

map:Map<String, Object>

the result map (preserving the original value structure in the YAML document)

org.springframework.beans.factory.config back to summary

public final Enum YamlProcessor.MatchStatus

extends Enum<YamlProcessor.MatchStatus>
Class Inheritance

Status returned from DocumentMatcher#matches(java.util.Properties).

Field Summary

Modifier and TypeField and Description
public static final YamlProcessor.MatchStatus
ABSTAIN

The matcher should not be considered.

public static final YamlProcessor.MatchStatus
FOUND

A match was found.

public static final YamlProcessor.MatchStatus
NOT_FOUND

No match was found.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static YamlProcessor.MatchStatus
getMostSpecific(YamlProcessor.MatchStatus a, YamlProcessor.MatchStatus b)

Compare two MatchStatus items, returning the most specific status.

public static YamlProcessor.MatchStatus
public static YamlProcessor.MatchStatus[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ABSTAINback to summary
public static final YamlProcessor.MatchStatus ABSTAIN

The matcher should not be considered.

FOUNDback to summary
public static final YamlProcessor.MatchStatus FOUND

A match was found.

NOT_FOUNDback to summary
public static final YamlProcessor.MatchStatus NOT_FOUND

No match was found.

Constructor Detail

MatchStatusback to summary
private MatchStatus()

Method Detail

getMostSpecificback to summary
public static YamlProcessor.MatchStatus getMostSpecific(YamlProcessor.MatchStatus a, YamlProcessor.MatchStatus b)

Compare two MatchStatus items, returning the most specific status.

valueOfback to summary
public static YamlProcessor.MatchStatus valueOf(String name)
valuesback to summary
public static YamlProcessor.MatchStatus[] values()
org.springframework.beans.factory.config back to summary

public final Enum YamlProcessor.ResolutionMethod

extends Enum<YamlProcessor.ResolutionMethod>
Class Inheritance

Method to use for resolving resources.

Field Summary

Modifier and TypeField and Description
public static final YamlProcessor.ResolutionMethod
FIRST_FOUND

Take the first resource in the list that exists and use just that.

public static final YamlProcessor.ResolutionMethod
OVERRIDE

Replace values from earlier in the list.

public static final YamlProcessor.ResolutionMethod
OVERRIDE_AND_IGNORE

Replace values from earlier in the list, ignoring any failures.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static YamlProcessor.ResolutionMethod
public static YamlProcessor.ResolutionMethod[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

FIRST_FOUNDback to summary
public static final YamlProcessor.ResolutionMethod FIRST_FOUND

Take the first resource in the list that exists and use just that.

OVERRIDEback to summary
public static final YamlProcessor.ResolutionMethod OVERRIDE

Replace values from earlier in the list.

OVERRIDE_AND_IGNOREback to summary
public static final YamlProcessor.ResolutionMethod OVERRIDE_AND_IGNORE

Replace values from earlier in the list, ignoring any failures.

Constructor Detail

ResolutionMethodback to summary
private ResolutionMethod()

Method Detail

valueOfback to summary
public static YamlProcessor.ResolutionMethod valueOf(String name)
valuesback to summary
public static YamlProcessor.ResolutionMethod[] values()
org.springframework.beans.factory.config back to summary

private Class YamlProcessor.SupportedTagInspector

extends Object
implements TagInspector
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.factory.config.YamlProcessor.SupportedTagInspector
All Implemented Interfaces
org.yaml.snakeyaml.inspector.TagInspector

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SupportedTagInspectorback to summary
private SupportedTagInspector()

Method Detail

isGlobalTagAllowedback to summary
public boolean isGlobalTagAllowed(Tag tag)

Implements org.yaml.snakeyaml.inspector.TagInspector.isGlobalTagAllowed.

Doc from org.yaml.snakeyaml.inspector.TagInspector.isGlobalTagAllowed.

Check

Parameters
tag:Tag

- the global tag to check

Returns:boolean

true when the custom global tag is allowed to create a custom Java instance

Annotations
@Override