formatDateTimes in gradle is private and thus cannot be set to 'true'
We are currently migrating our project from maven to gradle and noticed that the "formatDateTimes" property cannot be set in the gradle because it is private. We are using the latest 1.2.2 version. The property is in the README.md and is described as changeable.
Hi
Can you provide an example ?
Could not reproduce with following input:
test.json:
{
"type": "object",
"properties": {
"defaultFormat" : {
"type" : "string",
"format" : "date-time"
}
}
}
build.gradle:
jsonSchema2Pojo {
setSource(files("$projectDir/src/main/resources/json"))
formatDateTimes = true
}
generates class:
...
@Generated("jsonschema2pojo")
public class Test {
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", timezone = "UTC")
@JsonProperty("defaultFormat")
private Date defaultFormat;
...
whereas with formatDateTimes = true in build.gradle generates:
@Generated("jsonschema2pojo")
public class Test {
@JsonProperty("defaultFormat")
private Date defaultFormat;
Hi!
Unfortunatelly I am unable to provide a screenshot due to some restrictions on my work pc, the configuration looks like this and I get this error only for the formatDateTimes property. If I remove it I get no errors.
I also tried to stop all gradle daemons, clean gradle caches, invalidate idea's caches.
The error message is: Cannot access 'formatDateTimes': it is private in 'JsonSchemaExtension'
And I cannot provide the json schema because it contains sensitive info. But it works fine with maven.
plugins {
...
id("org.jsonschema2pojo") version "1.2.2"
}
jsonSchema2Pojo {
sourceFiles = files("/example")
targetPackage = "org.example"
includeHashcodeAndEquals = false
includeToString = false
includeAdditionalProperties = false
formatDateTimes = true <--- here I get an error
formatDates = true
dateType = "java.time.LocalDate"
dateTimeType = "java.time.OffsetDateTime"
useLongIntegers = true
useDoubleNumbers = false
}
Some questions:
- are you using gradle kotlin dsl (
*.kts) or groovy dsl - which gradle version is being used
I am using kotlin dsl, the gradle version is 7.4
It seems that gradle kotlin dsl behaves differently than groovy dsl. For now as a workaround you could use
setFormatDateTimes(true)
instead of
formatDateTimes = true
thanks for the option with the setter, but I have already tried it and it cannot resolve the setter also, as the property is "private" :(
I've also just noticed the customDateTimePattern option in the docs, maybe it will do the trick without formatDateTimes = true
thanks for the option with the setter, but I have already tried it and it cannot resolve the setter also, as the property is "private" :( I've also just noticed the
customDateTimePatternoption in the docs, maybe it will do the trick withoutformatDateTimes = true
That's weird - checked with following combinations and it worked fine
jsonSchema2Pojo {
sourceFiles = files("/src/main/resources/schema")
targetPackage = "my.pkg"
generateBuilders = false
setFormatDateTimes(true)
}
jsonSchema2Pojo {
sourceFiles = files("/src/main/resources/schema")
targetPackage = "my.pkg"
generateBuilders = false
isFormatDateTimes = true
}
Would be good to get a SSCCE (all company/work code could be stripped/replaced/reduced to bare minimum)
Just hit this exact issue myself. Also using kotlin dsl, also unable to show code :) I'll try to find the time to build a minimal demo later.