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

Empty yaml objects are not injected as properties #19095

Closed
jntakpe opened this issue Nov 22, 2019 · 1 comment
Closed

Empty yaml objects are not injected as properties #19095

jntakpe opened this issue Nov 22, 2019 · 1 comment
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@jntakpe
Copy link

jntakpe commented Nov 22, 2019

Spring Boot version: 2.2.1.RELEASE

Having the following properties

prefix:
  obj:
    foo:
      firstName: John
      lastName: Doe
    bar: {}

And given the following properties class

@ConstructorBinding
@ConfigurationProperties("prefix")
data class ObjProperties(val obj: Map<String, FooBarProperties>)

@ConstructorBinding
data class FooBarProperties(val firstName: String? = "", val lastName: String? = "")

I was expecting that injecting ObjProperties bean will result in having both foo property and bar property in obj map. Unfortunately, bar property is missing from the objmap.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 22, 2019
@mbhave mbhave added the for: team-attention An issue we'd like other members of the team to review label Nov 25, 2019
@wilkinsona wilkinsona changed the title Empty yaml objects are not injected has properties Empty yaml objects are not injected as properties Nov 27, 2019
@wilkinsona wilkinsona self-assigned this Nov 27, 2019
@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Nov 27, 2019
@wilkinsona
Copy link
Member

Thanks for the issue report, @jntakpe. We spent some time discussing this today and concluded that this it isn't something that we want to try and support. Configuration property binding is backed by Spring Framework's Environment and PropertySource abstractions. The later is a "source of name/value property pairs". As such, there's no way to represent the YAML-specific concept of an empty object that could then be used by the property binding to know that an empty instance of FooBarProperties should be created.

wilkinsona added a commit that referenced this issue Sep 10, 2024
Adding origin support caused an unexpected and unwanted change
in behavior where configuration property binding would fail. The
failure would occur because there was no way to convert from the
entry in the environment that represents the empty map to the
target type.

The commit changes the YAML loader to drop empty maps,
effectively reverting the map portion of
3bcbb0e and gh-21704. This aligns
the behavior with the decision we made in gh-19095.

Origin support for an empty list has been retained as it does not
have a negative effect on configuration property binding. Prior to
these changes, an empty YAML list was mapped to an origin tracked
value that contains an empty list. Fully reverting
3bcbb0e would have resulted in an
empty YAML list being mapped to an empty string. To avoid adding a
collection type to the environment, we now map an empty YAML list
to an origin tracked value that contains an empty string.

Closes gh-35403
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants