1

All of this was tested/tried on springboot 3.3.0.

Consider the following configuration class file:

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Map;

@ConfigurationProperties(prefix = "app")
public record AppProperties(Map<String, MapConfig> map, UseConfig config) {

    record MapConfig(String value1, String value2) {}
    record UseConfig(String use) {}
}

And now consider the following configuration yaml file:

app:
  map: <-- This is a Map<String, Object>
    key1: <-- This is a user defined key that I cannot control through enums, so it's a String
      ...
    key2:
      ...
  config:
    use: key1 <-- Use one key from the `app.map` keySet

What I want to do, is to provide a nice user experience by having hints provided by the IDE.

  • app.config.use suggestions should be [key1, key2].
  • app.config.use with value key3 should be marked as a configuration error
  1. I looked into how map are being tested as part of the spring-boot-configuration-metadata project.
  2. I looked into the Metadata Format :: Spring Boot docs

But it seems that I cannot provide dynamic hints based on the keys of a map.

I tried configuring hints manually, but couldn't find a way with the current value providers:

  • any
  • class-reference
  • handle-as
  • logger-name
  • spring-bean-reference
  • spring-profile-name

I would have expected something like that to fulfill my needs:


{
  "name": "app.config.use",
  "providers": [
    {
      "name": "property-source",
      "parameters": {
        "property": "app.map.keys"
      }
    }
  ]
}

Note that I'm using .keys to specify the key set of such property. Just as mentioned in the value hint doc which states:

If your property is of type Map, you can provide hints for both the keys and the values (but not for the map itself). The special .keys and .values suffixes must refer to the keys and the values, respectively.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.