I don’t understand what is problem clearly. When I searched it in google, I don’t decide my reponse model is problem or the json response is problem and should change. Which one? I can’t find solution for Kotlin. How I should solve this?
response JSON:
"data":{
"productInfo":{
"data":{
"toBarcode":"2704439285463",
"productJson":{
"p_no":"28420000",
"p_name":"ASA"
}
}
},
"moves":{
"data":[
{
"fisAcik":"MALVERENDEN",
"toBarcode":"2704439285463",
"toJson":{
"to_Hks_Adi":"DAĞITIM MERKEZİ"
},
"movementJson":{
"isleme_Tarihi":"21/12/2022 02:19:30"
}
}
]
}
}
Data.kt
data class Data(
val productInfo: ProductInfo,
val moves: Moves
)
data class Moves (
val data: List<MovesItem>
)
data class MovesItem (
@SerializedName("fisAcik")
val receiptExplanation: String,
val toBarcode: String,
val toJson: ToJson,
val movementJson: MovementJson
)
data class MovementJson (
@SerializedName("isleme_Tarihi")
val processDate: String
)
data class ToJson (
@SerializedName("to_Hks_Adi")
val toUnitHksName: String
)
data class ProductInfo (
val data: ProductInfoItems
)
data class ProductInfoItems (
val toBarcode: String,
val productJson: ProductJson
)
data class ProductJson (
@SerializedName("p_No")
val migrosProductNo: String,
@SerializedName("p_Name")
val migrosProductName: String
)
method that using to call request.
suspend fun dataGetInfo(@Body request: DataRequest): NetworkResult<BaseResponse<Data>>
2
Answers
This error was from my wrong request. I saw Ios has same error also when request with wrong value. So, for who will look this quesiton, they should understand it's not from response or kotlin. Check your value it is clearly what request need.
The framework you are using for this:
...fun dataGetInfo(@Body request: DataRequest)...
is implicitly taking a JSON request and deserializing.
The annotation
@SerializedName
is a from the Gson library, so I guessed that your framework must be using Gson. From that I was able to test using:which produces
So fundamentally your code is ok, but I think the problem is how the source JSON is "topped and tailed". To get that parse work, I was using
Notice how I removed, from your source,
"data":
since what you pasted is obviously not a JSON document. I guess, therefore, that this is where the problem occurs – something to do with the top or bottom of the JSON document or you need a container object around the JSON forData