[BUG] [Kotlin] 5.2.0 generic request type cause issue Platform class kotlin.Unit requires explicit JsonAdapter to be registered if requestBody is not provided
See original GitHub issueWhen using latest version 5.2.0. I have tested with 5.2.1-SNAPSHOT and has still this issue. This works with 5.1.1 version.
java.lang.IllegalArgumentException: Platform class kotlin.Unit requires explicit JsonAdapter to be registered
at com.squareup.moshi.ClassJsonAdapter$1.create(ClassJsonAdapter.java:75)
at com.squareup.moshi.Moshi.adapter(Moshi.java:145)
at com.squareup.moshi.Moshi.adapter(Moshi.java:105)
at com.squareup.moshi.Moshi.adapter(Moshi.java:79)
Spec:
openapi: 3.0.1
paths:
/v1/abcs/{id}/cancel:
patch:
tags:
- Abcs
operationId: cancelAbc
parameters:
- name: id
in: path
required: true
schema:
type: string
format: uuid
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/MockResponse'
MockResponse:
required:
- response
type: object
properties:
response:
$ref: '#/components/schemas/Response'
components:
schemas:
Response:
required:
- confirmationId
type: object
properties:
id:
type: string
format: uuid
confirmationId:
type: string
Note: no requestBody for patch.
Generated code:
suspend fun cancelAbc(id: java.util.UUID) : MockResponse{
val localVariableConfig = cancelAbcRequestConfig(id = id)
val localVarResponse = request<Unit, MockResponse>(
localVariableConfig
)
.....
}
data class MockResponse (
@Json(name = "response")
val response: Response
)
Here, the request type is Unit
.
while 5.1.1 generates only request<MockResponse>
no request type.
Extra related dependencies:
implementation("com.squareup.moshi:moshi-kotlin:1.12.0")
implementation "com.squareup.okhttp3:okhttp:4.9.0"
Issue Analytics
- State:
- Created 2 years ago
- Reactions:13
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Platform class kotlin.Unit requires explicit JsonAdapter to be ...
In a retrofit interface I have defined a method return type as ApiModel < Unit >. but when I call the method I...
Read more >[Solved]-Generics with moshi and retrofit-kotlin
I'm not sure what the best way to do this is, but the way I've done it is with KotlinJsonAdapterFactory. Create a data...
Read more >How to create a generic Moshi JsonAdapter that returns ...
It makes it easy to parse JSON into Java and Kotlin classes. The real-life problem. Recently I faced an issue where one of...
Read more >react router catch all 404 Code Example
Error : Node Sass version 5.0.0 is incompatible with ^4.0.0. ... Changing columns for table "users" requires Doctrine DBAL. Please install the ...
Read more >Retrieving reified generic arguments - hrach.dev
Kotlin has a great feature that will allow you to preserve generic type T for further work, not only type resolution.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
👍
When I add requestBody it works and I see generated code as follows:
Then
Changed to
The problem is
Unit
as request type when no explicit requestBody is added in specification of openAPI.