简体   繁体   English

我们如何使用 jsonschema2pojo 生成 Java 8 可选的 getter

[英]How can we generate Java 8 Optional getters using jsonschema2pojo

Generating java Pojo classes using gradle plugin jsonschema2pojo but i need to generate java8 optonal getter method使用 gradle 插件 jsonschema2pojo 生成 java Pojo 类,但我需要生成 java8 可选 getter 方法

Example.json示例.json

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

Generating getter method like below in Example.java:在 Example.java 中生成如下所示的 getter 方法:

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

But i need jav 8 Optional type getter method但我需要 jav 8 可选类型的 getter 方法

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

You can add useOptionalForGetters parameter into your plugin config您可以将useOptionalForGetters参数添加到您的插件配置中

jsonSchema2Pojo {

    useOptionalForGetters true

}

I have tested it with org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:1.0.2我已经用org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:1.0.2对其进行了测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM