Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formatDateTimes in gradle is private and thus cannot be set to 'true' #1642

Open
attebjorner opened this issue Nov 1, 2024 · 7 comments
Open

Comments

@attebjorner
Copy link

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.

@unkish
Copy link
Collaborator

unkish commented Nov 2, 2024

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;

@attebjorner
Copy link
Author

attebjorner commented Nov 2, 2024

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
}

@unkish
Copy link
Collaborator

unkish commented Nov 2, 2024

Some questions:

  • are you using gradle kotlin dsl (*.kts) or groovy dsl
  • which gradle version is being used

@unkish
Copy link
Collaborator

unkish commented Nov 3, 2024

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

@attebjorner
Copy link
Author

I am using kotlin dsl, the gradle version is 7.4

@attebjorner
Copy link
Author

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

@unkish
Copy link
Collaborator

unkish commented Nov 3, 2024

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

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants