-
Notifications
You must be signed in to change notification settings - Fork 18
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
KSP: Serde can't work with discrimantor #768
KSP: Serde can't work with discrimantor #768
Comments
@dstepanov next bug from micronaut-openapi :-) |
@dstepanov problem only with KSP, with java and KAPT all works fine. You can check java in the same scenario and compare introspection in the same project in branch |
Also can say that with |
@dstepanov You close it too early. Still have the same error: |
@dstepanov Please, reopen issue. It still doesn't work :-( |
@dstepanov Hi! Any news about this? |
Nope, need to check again |
@altro3 Looks like |
@dstepanov No, problem not here. I try to generate classes with prefix As you see, discriminator value must be I tried write test for KSP here - #833 , but every time I see problem with not found Introspected class, but in temp directory I see it. In my opinion, you need to write a test for this case and understand what the problem is with KSP. @dstepanov But without your help I won't be able to do this |
@dstepanov Interesting difference between introspection for KSP and KAPT (left is KSP): Intropected class (the same for KAP and KSP): @Serdeable
@JsonPropertyOrder(
Animal.JSON_PROPERTY_PROPERTY_CLASS,
Animal.JSON_PROPERTY_COLOR
)
@Generated("io.micronaut.openapi.generator.KotlinMicronautServerCodegen")
@JsonIgnoreProperties(
value = ["class"], // ignore manually set class, it will be automatically generated by Jackson during serialization
allowSetters = true // allows the class to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "class", visible = true)
@JsonSubTypes(
JsonSubTypes.Type(value = Bird::class, name = "ave"),
JsonSubTypes.Type(value = Mammal::class, name = "mammalia"),
JsonSubTypes.Type(value = Reptile::class, name = "reptilia")
)
open class Animal(
@field:Nullable
@field:Schema(name = "color", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@field:JsonProperty(JSON_PROPERTY_COLOR)
@field:JsonInclude(JsonInclude.Include.USE_DEFAULTS)
open var color: ColorEnum? = null,
@field:Nullable
@field:Schema(name = "class", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@field:JsonProperty(JSON_PROPERTY_PROPERTY_CLASS)
@field:JsonInclude(JsonInclude.Include.USE_DEFAULTS)
open var propertyClass: String? = null,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as Animal
if (propertyClass != other.propertyClass) return false
if (color != other.color) return false
return true
}
override fun hashCode(): Int {
var result = propertyClass?.hashCode() ?: 0
result = 31 * result + (color?.hashCode() ?: 0)
return result
}
override fun toString(): String {
return "Animal(propertyClass='$propertyClass', color='$color')"
}
companion object {
const val JSON_PROPERTY_PROPERTY_CLASS = "class"
const val JSON_PROPERTY_COLOR = "color"
}
} |
Problem in class As you see, you set I am 100% sure that we need a test, because there are at least 2 bugs for KSP |
* Add test for process KSP Json subtypes. See #768 * Correct test * Revert `Fix test` * Added new test with constructor argument annotations * Added new integration test for #875 * Use latest core --------- Co-authored-by: Denis Stepanov <[email protected]>
Get a sample application: https://github.com/altro3/micronaut3-bug/tree/kotlin (branch
kotlin
)Send simple request to endpoint
localhost:8080/test
And you will see exception:
Sample controller:
Sample model classes:
Bird
ColorEnum
Exception reproduce only with KSP.
IMPRTANT: For this problem it doesn' matter do you use
field:
prefix or not. It doesn't work in both casesExample Application
https://github.com/altro3/micronaut3-bug/tree/kotlin
Version
4.3.5
The text was updated successfully, but these errors were encountered: