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

Question: Is it possible to validate using Bean Validation for JsonSubTypes polymorfic deserialization? #3980

Open
gustavodaquino opened this issue Jun 13, 2023 · 2 comments
Labels
to-evaluate Issue that has been received but not yet evaluated

Comments

@gustavodaquino
Copy link

gustavodaquino commented Jun 13, 2023

Hello! I have a question regarding the usage of Bean Validation in Kotlin for subtypes in a polymorphic deserialization.
Here's an example that illustrates the scenario:

data class Shape(
    @NotBlank @Pattern(regexp = "SQUARE|CIRCLE") val type: String,
    @JsonTypeInfo(use = NAME, include = EXTERNAL_PROPERTY, property = "type")
    @JsonSubTypes(
        value = [
            Type(value = Square::class, name = "SQUARE"),
            Type(value = Circle::class, name = "CIRCLE")
        ]
    )
    val base: Base
)

data class Square(@Min(1) val side: Int) : Base()

data class Circle(@Min(1) val radius: Int) : Base()

sealed class Base

In the code above, the validation of the type property works fine. However, the validation for the properties of the subclasses is currently being ignored.

I would appreciate any help or guidance you can provide!

@gustavodaquino gustavodaquino added the to-evaluate Issue that has been received but not yet evaluated label Jun 13, 2023
@yawkat
Copy link
Member

yawkat commented Jun 13, 2023

im not sure how this is a jackson question, jackson does not perform bean validation.

@yihtserns
Copy link
Contributor

yihtserns commented Jun 13, 2023

the validation for the properties of the subclasses...

I think you mean validation is not performed on the value of base property.

If I remember correctly, to get Bean Validation to validate "inside" property value, you need to annotate that property with @Valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-evaluate Issue that has been received but not yet evaluated
Projects
None yet
Development

No branches or pull requests

3 participants