mbknor-jackson-jsonSchema icon indicating copy to clipboard operation
mbknor-jackson-jsonSchema copied to clipboard

@JsonProperty(required = false) is ignored

Open JoeryH opened this issue 4 years ago • 3 comments

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.

JoeryH avatar Feb 25 '21 13:02 JoeryH

Possible duplicate of https://github.com/mbknor/mbknor-jackson-jsonSchema/issues/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.

almson avatar Oct 31 '21 09:10 almson

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 avatar Oct 25 '23 07:10 harrismirza

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.

harrismirza avatar Oct 25 '23 08:10 harrismirza