Skip to content

Commit b5a51f6

Browse files
committed
Fix variation attributes deserializing
1 parent 7f5cbe0 commit b5a51f6

File tree

3 files changed

+5
-23
lines changed

3 files changed

+5
-23
lines changed

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/model/pos/WooPosVariationApiResponse.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ data class WooPosVariationApiResponse(
4949
val backordered: Boolean = false,
5050

5151
@SerializedName("attributes")
52-
val attributes: List<VariationAttribute> = emptyList(),
52+
val attributesJson: String = "",
5353

5454
@SerializedName("image")
5555
val image: VariationImage? = null,
@@ -60,17 +60,6 @@ data class WooPosVariationApiResponse(
6060
@SerializedName("name")
6161
val name: String = ""
6262
) {
63-
data class VariationAttribute(
64-
@SerializedName("id")
65-
val id: Long = 0L,
66-
67-
@SerializedName("name")
68-
val name: String = "",
69-
70-
@SerializedName("option")
71-
val option: String = ""
72-
)
73-
7463
data class VariationImage(
7564
@SerializedName("id")
7665
val id: Long = 0L,

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/pos/WooPosProductResponseToEntityMapper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fun WooPosVariationApiResponse.mapToPosVariationModel(
5757
stockStatus = this.stockStatus,
5858
manageStock = this.manageStock,
5959
backordered = this.backordered,
60-
attributesJson = this.attributes.toString(),
60+
attributesJson = this.attributesJson,
6161
imageUrl = this.image?.src ?: "",
6262
status = this.status,
6363
downloadable = this.downloadable

libs/fluxc-plugin/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/pos/WooPosVariationMapperTest.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ class WooPosVariationMapperTest {
2626
stockStatus = "instock",
2727
manageStock = true,
2828
backordered = false,
29-
attributes = listOf(
30-
WooPosVariationApiResponse.VariationAttribute(1, "Color", "Blue"),
31-
WooPosVariationApiResponse.VariationAttribute(2, "Size", "Large")
32-
),
29+
attributesJson = """[{"id":1,"name":"Color","option":"Blue"},{"id":2,"name":"Size","option":"Large"}]""",
3330
image = WooPosVariationApiResponse.VariationImage(
3431
id = 789,
3532
src = "https://example.com/image.jpg",
@@ -105,7 +102,7 @@ class WooPosVariationMapperTest {
105102
val response = WooPosVariationApiResponse(
106103
id = 123L,
107104
productId = 456L,
108-
attributes = emptyList()
105+
attributesJson = "[]"
109106
)
110107

111108
// When
@@ -121,11 +118,7 @@ class WooPosVariationMapperTest {
121118
val response = WooPosVariationApiResponse(
122119
id = 123L,
123120
productId = 456L,
124-
attributes = listOf(
125-
WooPosVariationApiResponse.VariationAttribute(1, "Color", "Red"),
126-
WooPosVariationApiResponse.VariationAttribute(2, "Size", "Medium"),
127-
WooPosVariationApiResponse.VariationAttribute(3, "Material", "Cotton")
128-
)
121+
attributesJson = """[{"id":1,"name":"Color","option":"Red"},{"id":2,"name":"Size","option":"Medium"},{"id":3,"name":"Material","option":"Cotton"}]"""
129122
)
130123

131124
// When

0 commit comments

Comments
 (0)