Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make use of custom types configurable in YamlProcessor #25152

Closed
sbrannen opened this issue May 28, 2020 · 1 comment
Closed

Make use of custom types configurable in YamlProcessor #25152

sbrannen opened this issue May 28, 2020 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

Overview

Since SnakeYaml allows for custom types to be loaded when they are specified inside the YAML document, we should make it possible to configure the types that can be constructed.

Proposal

Provide a mechanism in YamlProcessor for configuring the supported custom types for the Yaml instance created in org.springframework.beans.factory.config.YamlProcessor.createYaml().

For example, a new void setSupportedCustomTypes(Class<?>... types) method could be added to YamlProcessor. If no supported types are configured, the Yaml instance would be created as it is currently, without any restrictions. If supported types have been configured, the Yaml instance would be created with restrictions in place. The TypeLimitedConstructor recently introduced in Spring Boot can serve as inspiration for the latter.

Related Issues

@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels May 28, 2020
@sbrannen sbrannen modified the milestones: 5.2.7, 5.1.16 May 28, 2020
@sbrannen sbrannen added the for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x label May 28, 2020
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x labels May 28, 2020
@sbrannen sbrannen self-assigned this May 28, 2020
sbrannen added a commit that referenced this issue May 29, 2020
Prior to this commit, there was no easy way to restrict what types could
be loaded from a YAML document in subclasses of YamlProcessor such as
YamlPropertiesFactoryBean and YamlMapFactoryBean.

This commit introduces a setSupportedTypes(Class<?>...) method in
YamlProcessor in order to address this. If no supported types are
configured, all types 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.

Closes gh-25152
FelixFly pushed a commit to FelixFly/spring-framework that referenced this issue Aug 16, 2020
Prior to this commit, there was no easy way to restrict what types could
be loaded from a YAML document in subclasses of YamlProcessor such as
YamlPropertiesFactoryBean and YamlMapFactoryBean.

This commit introduces a setSupportedTypes(Class<?>...) method in
YamlProcessor in order to address this. If no supported types are
configured, all types 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.

Closes spring-projectsgh-25152
bclozel added a commit that referenced this issue Feb 9, 2021
`spring-beans` ships a `YamlProcessor` that's used as a base class by
`YamlMapFactoryBean` and `YamlPropertiesFactoryBean`. These
implementations have a clear use case: mapping application-internal Yaml
documents for configuration or infrastructure purposes.

Since this use case rarely requires extended types support from the
underlying library, and since we're offering ways to list custom types
(since #25152), we'll restrict to java standard types only by default.
This simplifies the setup and focuses the abstract class on the core
use cases.

Closes gh-26530
zx20110729 pushed a commit to zx20110729/spring-framework that referenced this issue Feb 18, 2022
Prior to this commit, there was no easy way to restrict what types could
be loaded from a YAML document in subclasses of YamlProcessor such as
YamlPropertiesFactoryBean and YamlMapFactoryBean.

This commit introduces a setSupportedTypes(Class<?>...) method in
YamlProcessor in order to address this. If no supported types are
configured, all types 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.

Closes spring-projectsgh-25152
@michaldo
Copy link

I would like to know purpose of this PR.
I'm going to replace snakeyaml suporting YAML 1.1 with snakeyaml-engine supporting YAML 1.2. But API is different and setSupportedCustomTypes is not easy replaceable.

I see that Spring Boot defines OriginTrackedYamlLoader, a subclass of YamlProcessor. It means clients can modify YamlProcessor - especially supported types - without explicite API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants