Skip to content

Commit eca33b8

Browse files
committed
use gson for LambdaHttp
1 parent 178f399 commit eca33b8

5 files changed

Lines changed: 26 additions & 20 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ dependencies {
175175
exclude(group = "org.slf4j")
176176
}
177177
includeLib("io.ktor:ktor-client-content-negotiation:$ktorVersion")
178-
includeLib("io.ktor:ktor-serialization-jackson:$ktorVersion")
178+
includeLib("io.ktor:ktor-serialization-gson:$ktorVersion")
179179
includeLib("com.fasterxml.jackson.core:jackson-annotations:2.21")
180180
includeLib("tools.jackson.core:jackson-core:$jacksonVersion")
181181
includeLib("tools.jackson.core:jackson-databind:$jacksonVersion")

src/main/kotlin/com/lambda/network/LambdaHttp.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18+
@file:Suppress("unused")
19+
1820
package com.lambda.network
1921

2022
import io.ktor.client.*
2123
import io.ktor.client.plugins.contentnegotiation.*
2224
import io.ktor.client.request.*
2325
import io.ktor.client.statement.*
2426
import io.ktor.http.*
25-
import io.ktor.serialization.jackson.*
27+
import io.ktor.serialization.gson.*
28+
import kotlinx.coroutines.Dispatchers
29+
import kotlinx.coroutines.withContext
2630
import java.io.File
2731
import java.io.OutputStream
2832

2933
val LAMBDA_HTTP = HttpClient {
3034
install(ContentNegotiation) {
31-
register(ContentType.Application.Json, JacksonConverter())
35+
gson()
3236
}
3337
}
3438

@@ -43,7 +47,9 @@ suspend inline fun HttpClient.download(url: String, output: OutputStream, block:
4347
val response = get(url, block)
4448
check(response.status.isSuccess()) { "Download for $url failed with non 2xx status code" }
4549

46-
output.write(response.readRawBytes())
50+
withContext(Dispatchers.IO) {
51+
output.write(response.readRawBytes())
52+
}
4753
}
4854

4955
suspend inline fun HttpClient.download(url: String, block: HttpRequestBuilder.() -> Unit) =

src/main/kotlin/com/lambda/network/api/v1/models/Authentication.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@
1717

1818
package com.lambda.network.api.v1.models
1919

20-
import com.fasterxml.jackson.annotation.JsonProperty
20+
import com.google.gson.annotations.SerializedName
2121

2222
data class Authentication(
23-
@JsonProperty("access_token")
23+
@SerializedName("access_token")
2424
val accessToken: String,
2525

26-
@JsonProperty("expires_in")
26+
@SerializedName("expires_in")
2727
val expiresIn: Long,
2828

29-
@JsonProperty("token_type")
29+
@SerializedName("token_type")
3030
val tokenType: String,
3131
) {
3232
data class Data(
33-
@JsonProperty("nbf")
33+
@SerializedName("nbf")
3434
val notBefore: Long,
3535

36-
@JsonProperty("iat")
36+
@SerializedName("iat")
3737
val issuedAt: Long,
3838

39-
@JsonProperty("exp")
39+
@SerializedName("exp")
4040
val expirationDate: Long,
4141

42-
@JsonProperty("data")
42+
@SerializedName("data")
4343
val data: Player,
4444
)
4545
}

src/main/kotlin/com/lambda/network/api/v1/models/Cape.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717

1818
package com.lambda.network.api.v1.models
1919

20-
import com.fasterxml.jackson.annotation.JsonProperty
20+
import com.google.gson.annotations.SerializedName
2121
import com.lambda.network.LambdaAPI
2222
import java.util.*
2323

2424
class Cape(
25-
@JsonProperty("uuid")
25+
@SerializedName("uuid")
2626
val uuid: UUID,
2727

28-
@JsonProperty("type")
28+
@SerializedName("type")
2929
val id: String,
3030
) {
3131
val url: String

src/main/kotlin/com/lambda/network/api/v1/models/Player.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717

1818
package com.lambda.network.api.v1.models
1919

20-
import com.fasterxml.jackson.annotation.JsonProperty
20+
import com.google.gson.annotations.SerializedName
2121
import java.util.*
2222

2323
data class Player(
24-
@JsonProperty("name")
24+
@SerializedName("name")
2525
val name: String,
2626

27-
@JsonProperty("id")
27+
@SerializedName("id")
2828
val uuid: UUID,
2929

30-
@JsonProperty("discord_id")
30+
@SerializedName("discord_id")
3131
val discordId: String,
3232

3333
// Whether the player is verified or not
34-
@JsonProperty("unsafe")
34+
@SerializedName("unsafe")
3535
val unsafe: Boolean,
3636
)

0 commit comments

Comments
 (0)