Created by: bkabrda
PR checklist
-
Read the contribution guidelines. -
Ran the shell script under ./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh,./bin/openapi3/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first. -
Filed the PR against the correct branch: master,4.1.x,5.0.x. Default:master. -
Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
CC @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04)
Description of the PR
This is my attempt to fix https://github.com/OpenAPITools/openapi-generator/issues/3435. Basically it makes sure that explicit null values can be sent for nullable fields:
- For a required nullable field, the
nullis always sent when that's the value. - For an optional (not required) nullable field, I introduced a simple new
Optionalclass withOptionalFilterthat make sure that thenullis sent if and only if it was set explicitly. AFAICS, the API of any of the generated classes didn't change in a backwards-incompatible way.
Discussion points:
- I added the
Optionalsincejava.util.Optionalwas added in JDK 8 and the templates still have support for previous Java versions. If desired, I can replace this with a different (third party) implementation pretty easily. - I didn't run the
./bin/...generators yet to keep the PR clean and reviewable. I'm planning to run it later. - I only added this for jackson, as I didn't figure out an easy way to do this for gson. I could try working on a different PR that would do this for gson, but that would take me a lot more time.