jsontypedef / json-typedef-codegen

A CLI tool that generates code from JSON Typedef schemas
https://jsontypedef.com/docs/tools/jtd-codegen
MIT License
160 stars 31 forks source link

Add nullability annotations in generated Java code #63

Open rbell-mfj opened 1 year ago

rbell-mfj commented 1 year ago

Generated Java code would have better null safety when used in Kotlin if there were an option to add nullability annotations

rbell-mfj commented 1 year ago

If I could get support from my employer to have someone contribute this, is there someone around here to accept a PR? Looks like the last PR merged in this repo was June 2021.

ucarion commented 1 year ago

Is the ask here to make it possible to customize what annotations jtd-codegen would use to indicate nullable/non-nullable fields?

And yes, I can accept PRs.

rbell-mfj commented 1 year ago

Is the ask here to make it possible to customize what annotations jtd-codegen would use to indicate nullable/non-nullable fields?

In short, yes.

The immediate goal is to have a way to add nullability annotations that allow the Kotlin compiler, when reading Java code generated by jtd-codegen, to know whether a property is nullable or not. (By default, it treats all Java types as unchecked with regard to nullability). The list of supported annotations for this is here

These would need to be in addition to the existing Jackson annotations.

Customizable sets of annotations for nullable/non-nullable is perhaps the best way to do this as it would enable other use cases.

That said, a simple on/off switch for one predetermined type of nullability annotation (from the list linked above) would also achieve the goal, if we could identify one that made sense as a de-facto standard or most commonly used.

Do you have a preference?