Skip to content

Commit 19358b4

Browse files
committed
Fix returned propery values: Integer numbers should be parsed into Long from the JSON response
1 parent 26e5434 commit 19358b4

34 files changed

+42
-35
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repositories {
1616
}
1717
1818
dependencies {
19-
implementation "com.recombee.apiclientkotlin:4.1.0"
19+
implementation "com.recombee.apiclientkotlin:4.1.1"
2020
}
2121
```
2222

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ plugins {
1818
}
1919

2020
group = "com.recombee"
21-
version = "4.1.0"
21+
version = "4.1.1"
2222

2323
repositories {
2424
mavenCentral()

src/main/kotlin/com/recombee/apiclientkotlin/RecombeeClient.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import kotlinx.coroutines.Dispatchers
1313
import kotlinx.coroutines.withContext
1414

1515
import com.google.gson.Gson
16+
import com.google.gson.GsonBuilder
1617
import com.google.gson.JsonElement
18+
import com.google.gson.ToNumberPolicy
1719
import com.google.gson.reflect.TypeToken
1820

1921
import okhttp3.*
@@ -29,6 +31,7 @@ import com.recombee.apiclientkotlin.exceptions.*
2931
import java.io.InterruptedIOException
3032
import java.net.SocketTimeoutException
3133

34+
3235
/**
3336
* Client for interacting with Recombee API.
3437
*
@@ -50,6 +53,10 @@ public class RecombeeClient(
5053
private val publicTokenBytes: ByteArray = publicToken.toByteArray(StandardCharsets.UTF_8)
5154
private val hostUri: String = getHostUri(baseUri, region)
5255

56+
public val gson: Gson = GsonBuilder()
57+
.setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
58+
.create()
59+
5360
private fun getRegionalBaseUri(region: Region): String {
5461
return when (region) {
5562
Region.ApSe -> "client-rapi-ap-se.recombee.com"
@@ -158,7 +165,7 @@ public class RecombeeClient(
158165
return OkHttp3Request.Builder()
159166
.url(processRequestUri(request))
160167
.post(createJsonRequestBody(request.bodyParameters))
161-
.header("User-Agent", "recombee-kotlin-api-client/4.1.0")
168+
.header("User-Agent", "recombee-kotlin-api-client/4.1.1")
162169
.build()
163170
}
164171

@@ -222,7 +229,7 @@ public class RecombeeClient(
222229
request is Batch -> parseBatchResponse(request, body) as ResponseType
223230
else -> {
224231
val type: Type = object : TypeToken<ResponseType>() {}.type
225-
Gson().fromJson<ResponseType>(body, type)
232+
gson.fromJson<ResponseType>(body, type)
226233
}
227234
}
228235
}

src/main/kotlin/com/recombee/apiclientkotlin/bindings/RecombeeBinding.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ package com.recombee.apiclientkotlin.bindings
33
/**
44
* Base class for the bindings
55
*/
6-
public abstract class RecombeeBinding
6+
public abstract class RecombeeBinding

src/main/kotlin/com/recombee/apiclientkotlin/bindings/Recommendation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ public data class Recommendation(
2020
public fun getValues(): Map<String, Any> {
2121
return values ?: throw IllegalStateException("The request was not meant to return values (use returnProperties parameter)")
2222
}
23-
}
23+
}

src/main/kotlin/com/recombee/apiclientkotlin/exceptions/ApiException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ package com.recombee.apiclientkotlin.exceptions
33
/**
44
* Base class for exceptions that occur because of errors in requests reported by API or because of a timeout
55
*/
6-
public open class ApiException(message: String) : Exception(message)
6+
public open class ApiException(message: String) : Exception(message)

src/main/kotlin/com/recombee/apiclientkotlin/exceptions/ApiIOException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ public open class ApiIOException(
1919
public val originalException: IOException? = null
2020
) : ApiException(
2121
message ?: originalException?.message ?: "Request unexpectedly failed"
22-
)
22+
)

src/main/kotlin/com/recombee/apiclientkotlin/exceptions/ApiTimeoutException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ public class ApiTimeoutException(
1313
request: Request<*>,
1414
originalException: IOException
1515
) : ApiIOException(
16-
request = request, message = "The request was not processed within ${request.timeout} ms", originalException=originalException)
16+
request = request, message = "The request was not processed within ${request.timeout} ms", originalException=originalException)

src/main/kotlin/com/recombee/apiclientkotlin/exceptions/ResponseException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ public class ResponseException(
1313
public val request: Request<*>,
1414
public val statusCode: Int,
1515
message: String
16-
) : ApiException(message)
16+
) : ApiException(message)

src/main/kotlin/com/recombee/apiclientkotlin/requests/AddBookmark.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class AddBookmark (
2323
public val cascadeCreate: Boolean? = true,
2424
public val recommId: String? = null,
2525
public val additionalData: Map<String, Any>? = null
26-
): Request<String>(1000) {
26+
): Request<String>(3000) {
2727

2828
/**
2929
* A string representing the path part of the URI.

0 commit comments

Comments
 (0)