Don't use visible = true in Java model classes#613
Don't use visible = true in Java model classes#613delenius wants to merge 1 commit intoOpenAPITools:masterfrom
Conversation
This causes errors when deserializing polymorphic classes.
|
Can you please provide some more information about this "polymorphic classes" case? My guess is that this Related to this topic, for |
|
visible = true is used to allow the discriminator to be visible in the json. It is generally needed when a discriminator is specified. As @jmini requested, please provide an example of an Open API Spec that exhibits the problem. The following issues from the swagger-codegen project may provide more details on this issue - these deal with the @JsonTypeInfo and may not be specific to "visible", but I think they might be helpful here.
|
|
The official documentation is here.
My understanding is that the difference is in what "layer" the property is seen. In order for Jackson to correctly use the discriminator property, the |
|
@0v1se , do your changes to the 3.2 branch require |
|
Oh, I just discovered something. The reason it didn't work for me was because I had registered a custom mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);whereas mine didn't. I can just retrieve and modify the existing apiClient.getJSON().getContext(Object.class).disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);BTW, one could argue that this setting should be a default as well. I had to add it in order to support POST requests with an empty body. I think the |
|
@delenius when you've time, can you please resolve the merge conflicts? |
|
@delenius we'll close this PR for the time being as it has been opened for a while. Please file a new one if you still want to add these changes to the master branch. |
|
IIRC, if "x-discriminator-value" is specified, then "visible" is required in the '@JsonTypeInfo'. Otherwise it can be false. To be clear, what I am suggesting is to set '@JsonTypeInfo(..., visible = true)' only when "x-discriminator-value" is non null. And set it to false (or not add it at all) otherwise. It seems that this may provide a solution to this issue |
This causes errors when deserializing polymorphic classes.
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{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\.master,3.1.x,4.0.x. Default:master.Description of the PR
When deserializing polymorphic classes using a discriminator property in the Java client, I get these errors from Jackson:
This is because we have
@JsonTypeInfo(..., visible = true)in the model classes. This PR removed thevisible = truepart, which fixes the problem.Tagging Java tech committee:
@bbdouglas (2017/07) @JFCote (2017/08) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01)