mbknor / mbknor-jackson-jsonSchema

Generate JSON Schema with Polymorphism using Jackson annotations
MIT License
235 stars 79 forks source link

@JsonProperty(required = false) is ignored #142

Open JoeryH opened 3 years ago

JoeryH commented 3 years ago

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 commented 3 years ago

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.

harrismirza commented 1 year ago

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 commented 1 year ago

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.