-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.embrace.android.embracesdk.internal.serialization | ||
|
||
import io.embrace.android.embracesdk.internal.logging.EmbLogger | ||
import java.io.InputStream | ||
import java.io.OutputStream | ||
import java.lang.reflect.Type | ||
|
||
internal class DecoratedSerializer( | ||
private val impl: PlatformSerializer, | ||
private val logger: EmbLogger | ||
) : PlatformSerializer { | ||
|
||
override fun <T> toJson(src: T): String { | ||
return serializerAction { impl.toJson(src) } | ||
Check warning on line 14 in embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt Codecov / codecov/patchembrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt#L14
|
||
} | ||
|
||
override fun <T> toJson(src: T, clz: Class<T>): String { | ||
return serializerAction { impl.toJson(src, clz) } | ||
} | ||
|
||
override fun <T> toJson(src: T, type: Type): String { | ||
return serializerAction { impl.toJson(src, type) } | ||
} | ||
|
||
override fun <T> toJson(any: T, clazz: Class<T>, outputStream: OutputStream) { | ||
return serializerAction { impl.toJson(any, clazz, outputStream) } | ||
Check warning on line 26 in embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt Codecov / codecov/patchembrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt#L26
|
||
} | ||
|
||
override fun <T> toJson(any: T, type: Type, outputStream: OutputStream) { | ||
return serializerAction { impl.toJson(any, type, outputStream) } | ||
Check warning on line 30 in embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt Codecov / codecov/patchembrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt#L30
|
||
} | ||
|
||
override fun <T> fromJson(json: String, clz: Class<T>): T { | ||
return serializerAction { impl.fromJson(json, clz) } | ||
} | ||
|
||
override fun <T> fromJson(json: String, type: Type): T { | ||
return serializerAction { impl.fromJson(json, type) } | ||
Check warning on line 38 in embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt Codecov / codecov/patchembrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt#L38
|
||
} | ||
|
||
override fun <T> fromJson(inputStream: InputStream, clz: Class<T>): T { | ||
return serializerAction { impl.fromJson(inputStream, clz) } | ||
Check warning on line 42 in embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt Codecov / codecov/patchembrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt#L42
|
||
} | ||
|
||
override fun <T> fromJson(inputStream: InputStream, type: Type): T { | ||
return serializerAction { impl.fromJson(inputStream, type) } | ||
Check warning on line 46 in embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt Codecov / codecov/patchembrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt#L46
|
||
} | ||
|
||
private fun <T> serializerAction(action: () -> T): T { | ||
try { | ||
return action() | ||
} catch (exc: Exception) { | ||
logger.logError("JSON serializer failed", exc) | ||
Check warning on line 53 in embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt Codecov / codecov/patchembrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/serialization/DecoratedSerializer.kt#L53
|
||
throw exc | ||
} | ||
} | ||
} |