hey, I came across a strange situation The test code is as follows

@SpringBootTest({
        "acc.data.cast[1]=int",
        "acc.data.cast[2]=long",
        "acc.data.cast[3]=float"
})
class BinderTest {


    @Autowired
    Environment environment;

    @Test
    void test() {
        Map<String, String> map = Binder.get(environment)
                .bind("acc", Bindable.mapOf(String.class, String.class))
                .orElseGet(Collections::emptyMap);
        System.out.println(map);
    }
}

Expected output: {data.cast[1]=int, data.cast[2]=long, data.cast[3]=float} Actual output: {data.cast.1=int, data.cast.2=long, data.cast.3=float}

I don't understand if this is normal output or a bug, can someone give me an answer

Comment From: mhalbritter

This is fine. data.cast.1 is the canonical name for acc.data.cast[1].

The environment normally translates the property names for you:

assertThat(environment.getProperty("acc.data.cast[1]")).isEqualTo("int");
assertThat(environment.getProperty("acc.data.cast.1")).isEqualTo("int");

In your case, the binder has to give a property name for the property and it chose to use the canonical name acc.data.cast.1.

Comment From: livk-cloud

这可以。data.cast.1是 的规范名称acc.data.cast[1]

环境通常会为您翻译属性名称:

assertThat(environment.getProperty("acc.data.cast[1]")).isEqualTo("int"); assertThat(environment.getProperty("acc.data.cast.1")).isEqualTo("int");

在您的情况下,活页夹必须为属性提供属性名称,并且它选择使用规范名称acc.data.cast.1

This is fine. data.cast.1 is the canonical name for acc.data.cast[1].

The environment normally translates the property names for you:

assertThat(environment.getProperty("acc.data.cast[1]")).isEqualTo("int"); assertThat(environment.getProperty("acc.data.cast.1")).isEqualTo("int");

In your case, the binder has to give a property name for the property and it chose to use the canonical name acc.data.cast.1.

In the current situation, what do I need to do to get the data returned by him to change from acc.data.cast.1 to acc.data.cast.[1] ?

Comment From: mhalbritter

I don't think that's possible. The code which creates the map key is in org.springframework.boot.context.properties.bind.MapBinder.EntryBinder#getKeyName and it will always use the dotted form.

Comment From: livk-cloud

我认为这是不可能的。创建地图键的代码位于 中org.springframework.boot.context.properties.bind.MapBinder.EntryBinder#getKeyName,它将始终使用点形式。

Thank you for your answer, maybe I should proceed from the returned map to meet my current needs