@@ -2,7 +2,6 @@ package com.afterpay.android.internal
2
2
3
3
import com.afterpay.android.BuildConfig
4
4
import kotlinx.serialization.Serializable
5
- import kotlinx.serialization.decodeFromString
6
5
import kotlinx.serialization.encodeToString
7
6
import kotlinx.serialization.json.Json
8
7
import java.io.InvalidObjectException
@@ -12,12 +11,13 @@ import javax.net.ssl.HttpsURLConnection
12
11
import kotlin.Exception
13
12
14
13
internal object ApiV3 {
14
+ private val json = Json { ignoreUnknownKeys = true }
15
15
16
16
internal inline fun <reified T , reified B > request (url : URL , method : HttpVerb , body : B ): Result <T > {
17
17
val connection = url.openConnection() as HttpsURLConnection
18
18
return try {
19
19
configure(connection, method)
20
- val payload = (body as ? String ) ? : Json .encodeToString(body)
20
+ val payload = (body as ? String ) ? : json .encodeToString(body)
21
21
22
22
val outputStreamWriter = OutputStreamWriter (connection.outputStream)
23
23
outputStreamWriter.write(payload)
@@ -26,13 +26,13 @@ internal object ApiV3 {
26
26
// TODO: Status code checking, error object decoding, bypass if return type is Unit
27
27
val data = connection.inputStream.bufferedReader().readText()
28
28
connection.inputStream.close()
29
- val result = Json .decodeFromString<T >(data)
29
+ val result = json .decodeFromString<T >(data)
30
30
Result .success(result)
31
31
} catch (exception: Exception ) {
32
32
try {
33
33
val data = connection.errorStream.bufferedReader().readText()
34
34
connection.errorStream.close()
35
- val result = Json .decodeFromString<ApiErrorV3 >(data)
35
+ val result = json .decodeFromString<ApiErrorV3 >(data)
36
36
Result .failure(InvalidObjectException (result.message))
37
37
} catch (_: Exception ) {
38
38
Result .failure(exception)
@@ -46,7 +46,7 @@ internal object ApiV3 {
46
46
val connection = url.openConnection() as HttpsURLConnection
47
47
return try {
48
48
configure(connection, method)
49
- val payload = (body as ? String ) ? : Json .encodeToString(body)
49
+ val payload = (body as ? String ) ? : json .encodeToString(body)
50
50
51
51
val outputStreamWriter = OutputStreamWriter (connection.outputStream)
52
52
outputStreamWriter.write(payload)
@@ -61,7 +61,7 @@ internal object ApiV3 {
61
61
try {
62
62
val data = connection.errorStream.bufferedReader().readText()
63
63
connection.errorStream.close()
64
- val result = Json .decodeFromString<ApiErrorV3 >(data)
64
+ val result = json .decodeFromString<ApiErrorV3 >(data)
65
65
Result .failure(InvalidObjectException (result.message))
66
66
} catch (_: Exception ) {
67
67
Result .failure(exception)
@@ -78,13 +78,13 @@ internal object ApiV3 {
78
78
79
79
val data = connection.inputStream.bufferedReader().readText()
80
80
connection.inputStream.close()
81
- val result = Json .decodeFromString<T >(data)
81
+ val result = json .decodeFromString<T >(data)
82
82
Result .success(result)
83
83
} catch (exception: Exception ) {
84
84
try {
85
85
val data = connection.errorStream.bufferedReader().readText()
86
86
connection.errorStream.close()
87
- val result = Json .decodeFromString<ApiErrorV3 >(data)
87
+ val result = json .decodeFromString<ApiErrorV3 >(data)
88
88
Result .failure(InvalidObjectException (result.message))
89
89
} catch (_: Exception ) {
90
90
Result .failure(exception)
0 commit comments