Skip to content

Commit

Permalink
explicit serialization of array objects
Browse files Browse the repository at this point in the history
  • Loading branch information
anonvt committed Aug 19, 2024
1 parent 7b9f828 commit 75d7997
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ data class ImpressionEvent (
val impressions: List<Impression>,
) {
fun toJsonObject(): JSONObject {
return JSONObject().put("impressions", impressions)
val array = JSONArray()
impressions.indices.map {
array.put(it, impressions[it].toJsonObject())
}
return JSONObject().put("impressions", array)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ data class PurchaseEvent(
val purchases: List<Purchase>
) {
fun toJsonObject(): JSONObject {
return JSONObject().put("purchases", purchases)
val array = JSONArray()
purchases.indices.map {
array.put(it, purchases[it].toJsonObject())
}
return JSONObject().put("purchases", array)
}

companion object{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.topsort.analytics.model.auctions

import org.json.JSONObject

data class AuctionRequest(
val auctions : List<Auction>
)
){
fun toJsonObject(): JSONObject {
return JSONObject().put("auctions", auctions)
}
}

0 comments on commit 75d7997

Please sign in to comment.