使用 Jackson 和 Lombok,有没有办法将 json 字段映射到静态变量

Using Jackson and Lombok, is there way to map json fields to static variables

我必须读取 JSON 文件并将环境 属性 作为静态变量注入。 这是 JSON

{
 "env":"staging",
 "index": "test",
 "indval": "testVal"
 
}

我只需要将 env 字段映射为我的 Class 中的静态字符串变量,使用 Jackson 和 Lombok

@Data
public class PubConf {

   public static String env;
   private String index;
   private String indval;

}

上面的问题我总是报错class

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "env"

感谢您解决此问题的想法

@Data
public class PubConf {

   private String env;
   private String index;
   private String indval;
 
    @JsonIgnore
    public static String statEnv;

    public void setEnv(String env) {
        PubConf.statEnv= env;
    }
}

来源:https://www.baeldung.com/spring-inject-static-field