-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[BUG] [Java] Nullable field failing when explicitly set to "null" #12549
Comments
The template that should be modified: |
I'm affected by this issue as well and I am interested in fixing it. I will submit a PR for it if @valmoz is not already working on it. |
+1 |
Hi, I prepared a PR for this #12630 |
+1 |
+1 |
I just ran into this too in 6.0.1! I managed to make it work by modifying the generated code to do the |
Hi @aaron-613 |
@valmoz very cool..! Wow 131 files changed!? That sounds like a lot. I stumbled onto another bug that is similar to this one, auto-generated validation code not being complete/correct. See my comment here: #12550 (comment) I was thinking I could attempt to fix myself if I just needed to update that |
Waiting the release, I'm using the @valmoz fix running:
|
@aaron-613 I just modified one mustache file... and then launched the generator to update the example files |
Im using v6.2.1 and am generating a Java client with:
When any property is null, even if including
Is this fixed by the PR above? It doesnt seem to be for Java |
This fix works for me (using v6.3.0), so should probably be closed |
I'm on the latest 6.4.0 and still seems to be an issue for arrays when explicitly set to null in the JSON response. The issue in the mustache seems to be this part, perhaps it should also do a check for isJsonNull()?
|
I have the same problem as @jaavaguy with version 6.4.0 i get code which runs into an exception: // ensure the optional json data is an array if present |
I'm also seeing this issue with a |
I'm also seeing this issue with |
+1 on this error. Even if required or nullable is not set, the exception for casting gson.JsonNull to gson.JsonObject is happening. Is there a known workaround to the issue on casting? |
Is there a known workaround? The client that I'm working on keeps failing because of the casting exception even though it's a valid case and my field has been marked as nullable. I don't want to force the server to return default values just to satisfy the client 😅 |
+1, still same issue in v6.6.0 |
the same occurs with java-spring generator with jackson-databind-nullable. which incorrectly assigns
|
@agrochmal this was only fixed in okhttp-gson generator, but feel free to submit a PR for java-spring |
Bug Report Checklist
Description
In our OpenAPI spec, we have a model with a nullable field called "prev_page_url".
If we test the generated code (with generator v6.0.0) omitting the parameter, it works correctly.
If instead we test setting the field explicitly to null we obtain the following error:
openapi-generator version
v6.0.0
OpenAPI declaration file content or URL
The parameter is defined here, and the main spec can be found here
Generation Details
Our github action can be found here
openapi-generator-cli generate -i ./openapi.yaml -g java -o ./generated/java/
Steps to reproduce
obtain a JSON response with the parameter set as follows:
Related issues/PRs
I couldn't find any...
Suggest a fix
In this case, Gson doesn't set the param to null, but to an instance of JsonNull class.
To check it should be able to change the pojo.mustache template in this way:
If you want, I can try to prepare a PR for this issue.
The text was updated successfully, but these errors were encountered: