【问题标题】:How can we generate Java 8 Optional getters using jsonschema2pojo我们如何使用 jsonschema2pojo 生成 Java 8 可选 getter
【发布时间】:2020-06-21 03:57:42
【问题描述】:

使用 gradle 插件 jsonschema2pojo 生成 java Pojo 类,但我需要生成 java8 可选 getter 方法

Example.json

{
  "type":"object",
  "properties": {
    "foo": {
      "type": "string"
    },
    }
}

在 Example.java 中生成如下 getter 方法:

@JsonProperty("foo")
public String getFoo() {
return foo;
}

但我需要 jav 8 可选类型的 getter 方法

@JsonProperty("foo")
public Optional<String> getFoo() {
return foo;
}

【问题讨论】:

    标签: java optional jsonschema2pojo


    【解决方案1】:

    您可以将useOptionalForGetters 参数添加到您的插件配置中

    jsonSchema2Pojo {
    
        useOptionalForGetters true
    
    }
    

    我已经用org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:1.0.2测试过了

    【讨论】:

      猜你喜欢
      • 2018-02-02
      • 2019-12-07
      • 2010-09-05
      • 2016-01-13
      • 1970-01-01
      • 1970-01-01
      • 2019-09-02
      • 2016-09-20
      • 2014-12-07
      相关资源
      最近更新 更多