相关疑难解决方法(0)

嵌套的对象列表的Spring配置属性元数据json

如何为嵌套的对象列表配置spring配置元数据json?

脚本

@ConfigurationProperties(prefix = "custom-config")
public class ConfigProperties {

    private boolean booleanProperty;
    private List<NestedObject> listProperty = new LinkedList<>();

    //getters and setters
}

public class NestedObject {

    private String stringProperty;
    private boolean booleanProperty;

    //getters and setters

}
Run Code Online (Sandbox Code Playgroud)

这是元数据json中自动生成的内容

{
  "groups": [{
    "name": "custom-config",
    "type": "testing.config.properties.ConfigProperties",
    "sourceType": "testing.config.properties.ConfigProperties"
  }],
  "properties": [
    {
      "name": "custom-config.boolean-property",
      "type": "java.lang.Boolean",
      "sourceType": "testing.config.properties.ConfigProperties",
      "defaultValue": false
    },
    {
      "name": "custom-config.list-property",
      "type": "java.util.List<testing.config.properties.NestedObject>",
      "sourceType": "testing.config.properties.ConfigProperties"
    }
  ],
  "hints": []
}
Run Code Online (Sandbox Code Playgroud)

如何在java代码或json中配置子属性?

如下所示,编辑器无法识别子属性.

在此输入图像描述

java spring json spring-mvc

6
推荐指数
1
解决办法
3849
查看次数

标签 统计

java ×1

json ×1

spring ×1

spring-mvc ×1