Skip to content

Commit

Permalink
Fix deserialization of RatesCalculationType
Browse files Browse the repository at this point in the history
  • Loading branch information
mvgreen committed Oct 11, 2024
1 parent c646397 commit 1c9d8cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.ecwid.apiclient.v3.jsontransformer.gson

import com.ecwid.apiclient.v3.dto.product.result.GetProductFiltersResult.ProductFilters
import com.ecwid.apiclient.v3.dto.profile.result.FetchedStoreProfile.RatesCalculationType
import com.ecwid.apiclient.v3.exception.JsonDeserializationException
import com.ecwid.apiclient.v3.impl.ParsedResponseWithExt
import com.ecwid.apiclient.v3.jsontransformer.JsonTransformer
import com.ecwid.apiclient.v3.jsontransformer.PolymorphicType
import com.ecwid.apiclient.v3.jsontransformer.gson.typeadapters.GsonNullableUpdatedValueTypeAdapterFactory
import com.ecwid.apiclient.v3.jsontransformer.gson.typeadapters.GsonPolymorphicDeserializer
import com.ecwid.apiclient.v3.jsontransformer.gson.typeadapters.GsonProductFiltersDeserializer
import com.ecwid.apiclient.v3.jsontransformer.gson.typeadapters.ParsedResponseWithExtDeserializer
import com.ecwid.apiclient.v3.jsontransformer.gson.typeadapters.*
import com.google.gson.*

class GsonTransformer(polymorphicTypes: List<PolymorphicType<*>>) : JsonTransformer {
Expand All @@ -23,6 +21,7 @@ class GsonTransformer(polymorphicTypes: List<PolymorphicType<*>>) : JsonTransfor
gsonBuilder.registerTypeAdapter(ProductFilters::class.java, GsonProductFiltersDeserializer())
gsonBuilder.registerTypeAdapter(ParsedResponseWithExt::class.java, ParsedResponseWithExtDeserializer())
gsonBuilder.registerTypeAdapterFactory(GsonNullableUpdatedValueTypeAdapterFactory)
gsonBuilder.registerTypeAdapter(RatesCalculationType::class.java, RatesCalculationTypeDeserializer())
}
.create()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ecwid.apiclient.v3.jsontransformer.gson.typeadapters

import com.ecwid.apiclient.v3.dto.profile.result.FetchedStoreProfile.RatesCalculationType
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import java.lang.reflect.Type

class RatesCalculationTypeDeserializer : JsonDeserializer<RatesCalculationType> {
override fun deserialize(
json: JsonElement,
typeOfT: Type,
context: JsonDeserializationContext
): RatesCalculationType? {
val strValue = json.asString
return RatesCalculationType.entries.firstOrNull { it.toString() == strValue }
}
}

0 comments on commit 1c9d8cb

Please sign in to comment.