I'm using swagger to define a contract with my web server. In the swagger file I define the REST endpoints and the request/response objects.
I would like to add the annotation @JsonInclude(Include.NON_NULL)
to a field in my swagger class. The swagger class is defined something like this:
MyObject:
discriminator: valueType
required:
- name
- description
properties:
name:
type: string
description:
type: string
value:
type: string
dbName:
type: string
When dbName
is null, I would like to not return it (not serialize it) so I'd get a response that looks like:
{
"name": "some_name",
"description": "my description",
"value": "some value"
}
If it were a java class I create, it would have been very easy to just define it as:
public class MyObject {
public String name;
public String description;
public String value;
@JsonInclude(Include.NON_NULL)
public String dbName;
}
But because that's an auto-generated class, I'm not sure how to make it happen.