-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing bug with constructor when multiple objects under an allOf, but…
… only one is the super class (#40)
- Loading branch information
Showing
6 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/test/resources/examples/polymorphicModels/sealed/models/Models.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package examples.polymorphicModels.sealed.models | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.annotation.JsonSubTypes | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
import javax.validation.constraints.NotNull | ||
import kotlin.Int | ||
import kotlin.String | ||
|
||
@JsonTypeInfo( | ||
use = JsonTypeInfo.Id.NAME, | ||
include = JsonTypeInfo.As.EXISTING_PROPERTY, | ||
property = "generation", | ||
visible = true | ||
) | ||
@JsonSubTypes( | ||
JsonSubTypes.Type( | ||
value = PolymorphicTypeOne::class, | ||
name = | ||
"PolymorphicTypeOne" | ||
), | ||
JsonSubTypes.Type( | ||
value = PolymorphicTypeTwo::class, | ||
name = | ||
"PolymorphicTypeTwo" | ||
) | ||
) | ||
sealed class PolymorphicSuperType( | ||
open val firstName: String, | ||
open val lastName: String | ||
) { | ||
abstract val generation: String | ||
} | ||
|
||
data class PolymorphicTypeOne( | ||
@param:JsonProperty("first_name") | ||
@get:JsonProperty("first_name") | ||
@get:NotNull | ||
override val firstName: String, | ||
@param:JsonProperty("last_name") | ||
@get:JsonProperty("last_name") | ||
@get:NotNull | ||
override val lastName: String, | ||
@param:JsonProperty("child_one_name") | ||
@get:JsonProperty("child_one_name") | ||
val childOneName: String? = null | ||
) : PolymorphicSuperType(firstName, lastName) { | ||
@get:JsonProperty("generation") | ||
@get:NotNull | ||
override val generation: String = "PolymorphicTypeOne" | ||
} | ||
|
||
data class PolymorphicTypeTwo( | ||
@param:JsonProperty("first_name") | ||
@get:JsonProperty("first_name") | ||
@get:NotNull | ||
override val firstName: String, | ||
@param:JsonProperty("last_name") | ||
@get:JsonProperty("last_name") | ||
@get:NotNull | ||
override val lastName: String, | ||
@param:JsonProperty("some_integer_propery") | ||
@get:JsonProperty("some_integer_propery") | ||
val someIntegerPropery: Int? = null, | ||
@param:JsonProperty("child_two_age") | ||
@get:JsonProperty("child_two_age") | ||
val childTwoAge: Int? = null | ||
) : PolymorphicSuperType(firstName, lastName) { | ||
@get:JsonProperty("generation") | ||
@get:NotNull | ||
override val generation: String = "PolymorphicTypeTwo" | ||
} |