Skip to content

Commit

Permalink
Directly register TypeAdapter with annotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
hafizrahman committed Dec 13, 2024
1 parent 3c423f4 commit 254cf5c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ class OrderEntityTest {
@Test
fun testDeserializeBatchOrderResponse() {
val testGson = GsonBuilder()
.registerTypeAdapter(
BatchOrderApiResponse.OrderResponse::class.java,
BatchOrderApiResponse.OrderResponseDeserializer())
.create()

val batchOrderJson = UnitTestUtils.getStringFromResourceFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package org.wordpress.android.fluxc.network.rest.wpcom.wc.order
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.annotations.JsonAdapter
import java.lang.reflect.Type
import org.wordpress.android.fluxc.network.Response

data class BatchOrderApiResponse(
val update: List<OrderResponse>
) : Response {
@JsonAdapter(OrderResponseDeserializer::class)
sealed class OrderResponse {
data class Success(
val order: OrderDto
Expand All @@ -30,7 +32,7 @@ data class BatchOrderApiResponse(
val status: Int
)

class OrderResponseDeserializer : JsonDeserializer<OrderResponse> {
private class OrderResponseDeserializer : JsonDeserializer<OrderResponse> {
override fun deserialize(
json: JsonElement,
typeOfT: Type,
Expand Down

0 comments on commit 254cf5c

Please sign in to comment.