Skip to content

Commit 6fce6d4

Browse files
committed
Allow subclasses to configure the Yaml instance
Provide an additional hook-point for YamlProcessor subclasses willing to change how the Yaml instance is configured. Also expose the default StrictMapAppenderConstructor so that they can compose a custom instance with it. Issue: SPR-12671
1 parent 0c856b3 commit 6fce6d4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ public void setResources(Resource... resources) {
130130
* Properties. Depending on the {@link #setResolutionMethod(ResolutionMethod)} not all
131131
* of the documents will be parsed.
132132
* @param callback a callback to delegate to once matching documents are found
133+
* @see #createYaml()
133134
*/
134135
protected void process(MatchCallback callback) {
135-
Yaml yaml = new Yaml(new StrictMapAppenderConstructor());
136+
Yaml yaml = createYaml();
136137
for (Resource resource : this.resources) {
137138
boolean found = process(callback, yaml, resource);
138139
if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND && found) {
@@ -141,6 +142,13 @@ protected void process(MatchCallback callback) {
141142
}
142143
}
143144

145+
/**
146+
* Create the {@link Yaml} instance to use.
147+
*/
148+
protected Yaml createYaml() {
149+
return new Yaml(new StrictMapAppenderConstructor());
150+
}
151+
144152
private boolean process(MatchCallback callback, Yaml yaml, Resource resource) {
145153
int count = 0;
146154
try {
@@ -331,7 +339,7 @@ public interface DocumentMatcher {
331339
/**
332340
* Status returned from {@link DocumentMatcher#matches(java.util.Properties)}
333341
*/
334-
public static enum MatchStatus {
342+
public enum MatchStatus {
335343

336344
/**
337345
* A match was found.
@@ -360,7 +368,7 @@ public static MatchStatus getMostSpecific(MatchStatus a, MatchStatus b) {
360368
/**
361369
* Method to use for resolving resources.
362370
*/
363-
public static enum ResolutionMethod {
371+
public enum ResolutionMethod {
364372

365373
/**
366374
* Replace values from earlier in the list.
@@ -382,7 +390,7 @@ public static enum ResolutionMethod {
382390
/**
383391
* A specialized {@link Constructor} that checks for duplicate keys.
384392
*/
385-
private static class StrictMapAppenderConstructor extends Constructor {
393+
protected static class StrictMapAppenderConstructor extends Constructor {
386394

387395
public StrictMapAppenderConstructor() {
388396
super();

0 commit comments

Comments
 (0)