Skip to content
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

@JsonProperty(required = false) is ignored #142

Open
JoeryH opened this issue Feb 25, 2021 · 3 comments
Open

@JsonProperty(required = false) is ignored #142

JoeryH opened this issue Feb 25, 2021 · 3 comments

Comments

@JoeryH
Copy link

JoeryH commented Feb 25, 2021

I am using Kotlin, but I think this applies to all languages:

@JsonProperty(required = false)
val optionalDefaultWithAnnotation: String = "Hello"

The resulting shema will include this field as required, effectively ignoring the annotation.

@almson
Copy link

almson commented Oct 31, 2021

Possible duplicate of #132

Not sure about Kotlin and val, but similar thing happens for non-boxed primitives. Basically this field is always present when you're serializing an object, but optional when deserializing. Unfortunately, there's no way to tell jsonSchema which kind of schema you're looking for.

@harrismirza
Copy link

Yeah, I've hit this with primitives as well, maybe it's worth having an config option for not forcing primitives to be required?

@harrismirza
Copy link

This might also be worth making a seperate issue, but if you set a default value for a primitive through the use of @JsonSchemaDefault, it also adds the property as required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants