Description
Describe the bug
Since @JsonUnwrapped
has been broken in 2.6.0 I still not able to make @JsonUnwrapped
work with my Kotlin data classes despite numerous fixes:
- 2.6.0 of springdoc-openapi-starter-webmvc-ui seems to introduce a regression when using @JsonUnwrapped & @Delegate #2682
- @JsonUnwrapped is ignored in new version of lib #2856
To Reproduce
data class ContactCreateRequest(
@JsonUnwrapped
val person: Person,
@Schema(required = false)
@JsonProperty("labels", required = false)
val labels: List<String>? = null,
)
data class Person(
@Schema(required = true, example = "Oscar Claude Monet")
@JsonProperty("name", required = true)
val name: String,
@Schema(example = "+38051231412")
@JsonProperty("phone")
val phone: String? = null,
@Schema(required = true, example = "oscar.monet@lafrance.fr")
@JsonProperty(value = "email", required = true)
val email: String,
)
This example in a sample Spring Boot project:
Dependencies
- Kotlin 2.1.10
org.springdoc:springdoc-openapi-starter-webmvc-api:2.8.4
org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.4
org.springframework.boot:spring-boot-....:3.4.2
Activity
wingsofovnia commentedon Jan 29, 2025
I did some research and figured out that while this does not work:
this does:
The decompiled byte code for those look like that:
vs
Funny thing is that if I try to replicate the first approach with pure Java,
@JsonCreator
s with@JsonUnwrapped
are not supported yet:This must be the Kotlin plugin doing some magic on top of default Jackson. This however is expected to change in the next Jackson minor release with FasterXML/jackson-databind#1467 merge.
Given that in this example
ContactCreateRequest
used for request body, it is deserialisation "view" that should be considered. It looks like the lookup for@JsonUnwrapped
since 2.5.0 has been reduced to looking at field annotations only.Both for Kotlin support and upcoming support of creators + unwrapped, I believe springdoc should bring the support back at looking for
@JsonUnwrapped
in creators and should distinguish between deserialisation and serialisation configurations.[-]`@JsonUnwrapped` is not still broken since 2.5[/-][+]`@JsonUnwrapped` behaves differently in Kotlin since 2.6[/+][-]`@JsonUnwrapped` behaves differently in Kotlin since 2.6[/-][+]`@JsonUnwrapped` is not still broken since 2.5[/+][-]`@JsonUnwrapped` is not still broken since 2.5[/-][+]`@JsonUnwrapped` is still broken since 2.5[/+]bnasslahsen commentedon Feb 8, 2025
@wingsofovnia,
There is no code in Springdoc responsible for
JsonUnwrapped
causing this behavior.Looks like i will count on your deeper analysis!
wingsofovnia commentedon Feb 8, 2025
@bnasslahsen there is though. I am afraid this is a bug in
PolymorphicModelConverter#resolve
.I've just replicated the issue on 2.8.4. This condiiton:
springdoc-openapi/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/converters/PolymorphicModelConverter.java
Lines 123 to 126 in 28c66e1
Is not going through because the annotation is on the getter, which is valid placement of this annotation too. Once I force this via debugger:
springdoc-openapi/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/converters/PolymorphicModelConverter.java
Line 126 in 28c66e1
The type is properly unwrapped.
Please re-open the ticket.
@JsonUnwrapped
&@Schema
on props not fields only #2894bnasslahsen commentedon Feb 8, 2025
@wingsofovnia,
I am merging your PR now.
didjoman commentedon Feb 18, 2025
Hi,
I have an issue with the fix.
If you have a class like the next one, then the
isUnwrapped
boolean in thePolymorphicModelConverter
is nowfalse
, but it wastrue
before :I am talking about this line:
Before, isUnwrapped was true:
springdoc-openapi/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/converters/PolymorphicModelConverter.java
Lines 123 to 124 in 6b7c7eb
Now, isUnwrapped is false:
springdoc-openapi/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/converters/PolymorphicModelConverter.java
Lines 125 to 128 in 165f0eb
Wouldn't there be an other way to get the annotation ?
3 remaining items