mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 14:40:53 +00:00
[kotlin][client] bytearray conversion (#2166)
* use kotlin.String for ByteArray fields (type: string, format: byte) * revert "use kotlin.String for ByteArray fields (type: string, format: byte)" * add ByteArrayAdapter for string <-> ByteArray conversion with moshi
This commit is contained in:
parent
b4b8c28b2a
commit
aace459217
@ -164,5 +164,6 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
|
|||||||
supportingFiles.add(new SupportingFile("infrastructure/ResponseExtensions.kt.mustache", infrastructureFolder, "ResponseExtensions.kt"));
|
supportingFiles.add(new SupportingFile("infrastructure/ResponseExtensions.kt.mustache", infrastructureFolder, "ResponseExtensions.kt"));
|
||||||
supportingFiles.add(new SupportingFile("infrastructure/Serializer.kt.mustache", infrastructureFolder, "Serializer.kt"));
|
supportingFiles.add(new SupportingFile("infrastructure/Serializer.kt.mustache", infrastructureFolder, "Serializer.kt"));
|
||||||
supportingFiles.add(new SupportingFile("infrastructure/Errors.kt.mustache", infrastructureFolder, "Errors.kt"));
|
supportingFiles.add(new SupportingFile("infrastructure/Errors.kt.mustache", infrastructureFolder, "Errors.kt"));
|
||||||
|
supportingFiles.add(new SupportingFile("infrastructure/ByteArrayAdapter.kt.mustache", infrastructureFolder, "ByteArrayAdapter.kt"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,9 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
fun toJson(uuid: UUID) = uuid.toString()
|
fun toJson(uuid: UUID) = uuid.toString()
|
||||||
@FromJson
|
@FromJson
|
||||||
fun fromJson(s: String) = UUID.fromString(s)
|
fun fromJson(s: String) = UUID.fromString(s)
|
||||||
}).build().adapter(T::class.java).fromJson(body.source())
|
})
|
||||||
|
.add(ByteArrayAdapter())
|
||||||
|
.build().adapter(T::class.java).fromJson(body.source())
|
||||||
else -> TODO()
|
else -> TODO()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package {{packageName}}.infrastructure
|
||||||
|
|
||||||
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.ToJson
|
||||||
|
|
||||||
|
class ByteArrayAdapter {
|
||||||
|
@ToJson
|
||||||
|
fun toJson(data: ByteArray): String = String(data)
|
||||||
|
|
||||||
|
@FromJson
|
||||||
|
fun fromJson(data: String): ByteArray = data.toByteArray()
|
||||||
|
}
|
@ -60,7 +60,9 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
fun toJson(uuid: UUID) = uuid.toString()
|
fun toJson(uuid: UUID) = uuid.toString()
|
||||||
@FromJson
|
@FromJson
|
||||||
fun fromJson(s: String) = UUID.fromString(s)
|
fun fromJson(s: String) = UUID.fromString(s)
|
||||||
}).build().adapter(T::class.java).fromJson(body.source())
|
})
|
||||||
|
.add(ByteArrayAdapter())
|
||||||
|
.build().adapter(T::class.java).fromJson(body.source())
|
||||||
else -> TODO()
|
else -> TODO()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.ToJson
|
||||||
|
|
||||||
|
class ByteArrayAdapter {
|
||||||
|
@ToJson
|
||||||
|
fun toJson(data: ByteArray): String = String(data)
|
||||||
|
|
||||||
|
@FromJson
|
||||||
|
fun fromJson(data: String): ByteArray = data.toByteArray()
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user