Skip to content

Commit

Permalink
Merge pull request #438 from Ecwid/fix_ratesCalculationType
Browse files Browse the repository at this point in the history
Fix deserialization of RatesCalculationType
  • Loading branch information
mvgreen authored Oct 14, 2024
2 parents c646397 + 87d4a45 commit dd293d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ data class FetchedStoreProfile(
app;

override fun toString(): String {
return asApiString()
}

fun asApiString(): String {
return super.toString().replace("_", "-")
}
}
Expand Down
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.asApiString() == strValue }
}
}

0 comments on commit dd293d5

Please sign in to comment.