0

Generating java Pojo classes using gradle plugin jsonschema2pojo but i need to generate java8 optonal getter method

Example.json

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

Generating getter method like below in Example.java:

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

But i need jav 8 Optional type getter method

@JsonProperty("foo")
public Optional<String> getFoo() {
return foo;
}
Naman
  • 27,789
  • 26
  • 218
  • 353
G SriHAri
  • 706
  • 2
  • 9
  • 27

1 Answers1

2

You can add useOptionalForGetters parameter into your plugin config

jsonSchema2Pojo {

    useOptionalForGetters true

}

I have tested it with org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:1.0.2

Nonika
  • 2,490
  • 13
  • 15