-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
JsonTypeInfo.As.PROPERTY
type id, property with same name, result in duplicate JSON property
#2022
Comments
I think Swagger should use |
JsonTypeInfo.As.PROPERTY
type id, property with same name, result in duplicate JSON property
I experimented with the various When I use @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "errorType", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = SpecificError.class, name = "SpecificError"),
})
public class GeneralError {
@JsonProperty("errorType")
private String errorType = null; I'll get this: {"errorType" : null, "message" : "message"} |
Yes, the intention is that Now... the problem that results in double-writing for |
Thanks for your valuable input and the analysis that was necessary for that. The only work-around I see so far is to use @JsonProperty("errorType")
@JsonInclude(JsonInclude.Include.NON_NULL)
private String errorType = null; However, as this is generated code it'll involve some ugly post-generating code manipulation. I know I can set the |
One suggestion: if you have not considered mix-in annotations yet, maybe consider those? They are designed to be used on 3rd party libraries where author has no control. |
@cowtowncoder My 1 or 2 cents worth on this topic: should we consider implementing a new strategy that behaves like |
@nickshoe I am not sure what you mean. |
@cowtowncoder ok, but would it be working without errors also during deserialization? If I remember correctly, removing the discriminator property from the POJO will make the deserialization process raise an "unrecognized field" exception. |
@cowtowncoder I was wrong in my last comment, that happens only if one uses |
@nickshoe Yes, I think you are right: |
Origin: https://stackoverflow.com/q/50163882/131929
The Swagger Java codegen produces a class like this:
The Jackson serializer, version 2.9.4, produces JSON that includes the
errorType
property twice:My test bed is as follows:
I'm not 100% sure if Jackson is supposed to behave like that given the annotations you see above. Based on what I read in the
JsonTypeInfo
Javadoc it seems incorrect. However, I also raised this as swagger-api/swagger-codegen#8137.The text was updated successfully, but these errors were encountered: