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

includeAdditionalProperties cannot work when annotationStyle is 'gson' #10

Closed
KengoTODA opened this issue Sep 4, 2020 · 1 comment
Closed

Comments

@KengoTODA
Copy link
Contributor

Here is my MCVE project. You can find the following configurations in build.gradle:

jsonSchema2Pojo {
  source = files('src/schema/schema.json')
  targetPackage = 'com.example'
  annotationStyle = 'gson'
  includeAdditionalProperties = true
}

When you run ./gradlew generateJsonSchema2Pojo --info in this MCVE project, you'll find that the generated class has no additionalProperties. You'll also find that the includeAdditionalProperties option is not provided to the jsonschema2pojo's Java API. If I set 'none' to annotationStyle, includeAdditionalProperties is not provided to the Java API either, but it actually generates additionalProperties field.

Here is INFO level log for your reference:

> Task :generateJsonSchema2Pojo
Caching disabled for task ':generateJsonSchema2Pojo' because:
  Build cache is disabled
  Caching has not been enabled for the task
Task ':generateJsonSchema2Pojo' is not up-to-date because:
  Output property '$1' file /home/kengo/github/js2p-gradle-reproduction/build/generated-sources/js2p has been removed.
  Output property '$1' file /home/kengo/github/js2p-gradle-reproduction/build/generated-sources/js2p/com has been removed.
  Output property '$1' file /home/kengo/github/js2p-gradle-reproduction/build/generated-sources/js2p/com/example has been removed.
Using this configuration:
generateBuilders = false
includeJsonTypeInfoAnnotation = false
usePrimitives = false
source = [/home/kengo/github/js2p-gradle-reproduction/src/schema/schema.json]
targetDirectory = /home/kengo/github/js2p-gradle-reproduction/build/generated-sources/js2p
targetPackage = com.example
propertyWordDelimiters = [-,  , _]
useLongIntegers = false
useBigIntegers = false
useDoubleNumbers = true
useBigDecimals = false
includeHashcodeAndEquals = true
includeConstructors = false
constructorsRequiredPropertiesOnly = false
includeRequiredPropertiesConstructor = false
includeAllPropertiesConstructor = true
includeCopyConstructor = false
includeToString = true
toStringExcludes = []
annotationStyle = gson
useTitleAsClassname = false
inclusionLevel = class org.jsonschema2pojo.InclusionLevel
customAnnotator = org.jsonschema2pojo.NoopAnnotator
customRuleFactory = org.jsonschema2pojo.rules.RuleFactory
includeJsr303Annotations = false
includeJsr305Annotations = false
useOptionalForGetters = false
sourceType = jsonschema
removeOldOutput = false
outputEncoding = UTF-8
useJodaDates = false
useJodaLocalDates = false
useJodaLocalTimes = false
dateTimeType = null
dateType = null
timeType = null
parcelable = false
serializable = false
initializeCollections = true
classNamePrefix = 
classNameSuffix = 
fileExtensions = []
includeGetters = true
includeSetters = true
targetVersion = 1.6
includeDynamicAccessors = false
includeDynamicGetters = false
includeDynamicSetters = false
includeDynamicBuilders = false
formatDates = false
formatTimes = false
formatDateTimes = false
customDatePattern = null
customTimePattern = null
customDateTimePattern = null
refFragmentPathDelimiters = #/.
sourceSortOrder = OS
targetLanguage = null
formatTypeMapping = [:]
useInnerClassBuilders = false
includeConstructorPropertiesAnnotation = false
     
Initializing class com.github.eirnym.js2p.GradleRuleLogger
:generateJsonSchema2Pojo (Thread[Execution worker for ':',5,main]) completed. Took 0.014 secs.
@KengoTODA
Copy link
Contributor Author

I found that this problem comes from the core jsonschema2pojo implementation:

https://github.com/joelittlejohn/jsonschema2pojo/blob/47456b34e5a028e0c8d56d3ca00a8e57be509ac5/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GsonAnnotator.java#L59

I'll use another annotation style to avoid. Thank you :)

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

1 participant