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

Fix for #174 - Flag to use Jackson2's required for optional #179

Closed
wants to merge 1 commit into from

Conversation

Yona-Appletree
Copy link
Contributor

Adds a flag which enables use of the Jackson2 optional concept to control the default optionality status for properties. Allows use of custom Jackson2 module logic to control optionality instead of relying on optional annotations alone.

My use case is to allow correct handling of Kotlin's optional properties, for which there are no runtime-readable annotations generated.

…required to control emitted property optionality
@vojtechhabarta
Copy link
Owner

Thanks for this PR.
I think you are right with your comment about JaxbAnnotationIntrospector.hasRequiredMarker(). I checked it and submitted fix (FasterXML/jackson-modules-base#32).

@JsonProperty(required = true) doesn't work because by default we register all Jackson2 modules which results in having JaxbAnnotationIntrospector before JacksonAnnotationIntrospector. You can try to set disableJackson2ModuleDiscovery parameter to true.

I am not sure how to change typescript-generator configuration so that all this works well together, maybe we will also need to change how Jackson2 modules are configured, give me some time.

@Yona-Appletree
Copy link
Contributor Author

So, in the case of my project, this actually does work, I think because I don't have the Jaxb module or similar, I haven't looked too far into it. But when using the kotlin module, the required flag is set correctly, so will likely work for other Kotlin folks.

As you said, perhaps there could be a setting to specify which Jackson2 modules are included, by class name pattern list or similar.

@vojtechhabarta
Copy link
Owner

@Yona-Appletree I reimplemented this feature with different configuration - added optionalProperties, and deprecated declarePropertiesAsOptional. I also changed how typescript-generator loads Jackson2 modules (motivated by JaxbAnnotationIntrospector.hasRequiredMarker() bug).

Could you please review new PR, at least Kotlin part?

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

Successfully merging this pull request may close these issues.

2 participants