Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deserialization of RatesCalculationType #438

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
}
}
Loading