Skip to content

fix: Correct model nullability and make strict JSON deserialization opt-in - #130

Merged
HofmeisterAn merged 4 commits into
testcontainers:mainfrom
brianrourkeboll:nullability-workaround
Nov 14, 2026
Merged

HofmeisterAn merged 4 commits into
testcontainers:mainfrom
brianrourkeboll:nullability-workaround

Conversation

@brianrourkeboll

Copy link
Copy Markdown

Workaround for #129.

If and when the nullable annotations are fixed, the two explicit disablings should be removed.

@HofmeisterAn HofmeisterAn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the issue and the PR. The model classes are generated by tools/specgen, and the bug is there. It only marks pointers and omitempty fields as nullable, but Go also writes nil maps and slices as null.

I think it's better to fix the generator than to turn the switches off in the library, because that would hide the wrong annotations. It would also make them correct at compile time for consumers.

@brianrourkeboll

Copy link
Copy Markdown
Author

I think it's better to fix the generator than to turn the switches off in the library

Yes, if we can make the annotations accurate, that would be best. And once they are accurate, we would want to turn these switches on, as in the first commit here (they're off by default for backwards compatibility).

@HofmeisterAn

Copy link
Copy Markdown
Collaborator

I thought about this once more, and we probably need a mixed approach. Improve the nullable information in the generator and make the library more resilient to global STJ configurations.

This isn't only about wrong annotations in the library. There are many different container runtime backends and API versions, and they may not all follow the same nullability, so an unexpected null shouldn't fail a whole call.

@HofmeisterAn HofmeisterAn added the enhancement New feature or request label Nov 14, 2026
@HofmeisterAn HofmeisterAn changed the title Work around nullability annotations mismatches fix: Correct model nullability and make strict JSON deserialization opt-in Nov 14, 2026

@HofmeisterAn HofmeisterAn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@HofmeisterAn
HofmeisterAn merged commit 672fd12 into testcontainers:main Nov 14, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants