Hello all, Iโ€™m getting error when I try deserializ...
# serialization
s
Hello all, Iโ€™m getting error when I try deserialize an object from JSON using Kotlin Serialization. I get the following error ๐Ÿ‘‡
Hereโ€™s my JSON file ๐Ÿ‘‡
Copy code
[
  {
    "emoji": "๐Ÿ˜",
    "description": "Love",
    "category": "this is category"
  },
  {
    "emoji": "๐Ÿš€",
    "description": "Rocket",
    "category": "this is category"
  },
  {
    "emoji": "โœ…",
    "description": "Check",
    "category": "this is category"
  },
  {
    "emoji": "๐Ÿ›",
    "description": "Shopping",
    "category": "this is category"
  },
  {
    "emoji": "๐Ÿ”ฅ",
    "description": "Fire",
    "category": "this is category"
  }
]
Hereโ€™s the simple code snippet ๐Ÿ‘‡
Copy code
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.*
import model.AllEmojiItem
import java.io.File
import java.util.*

fun main() {
    val scanner = Scanner(System.`in`)
    println("Enter the file path: ")
    val filePath = scanner.nextLine()
    println("File is $filePath")
    val emojiJson = File(filePath).readText()

    // reading filePath ๐Ÿ‘€
    println("Reading filePath ๐Ÿ‘€... \n")

    // decode from string
    val decodeEmoji = Json.decodeFromString<AllEmojiItem>(emojiJson)
    println("Decoding :$decodeEmoji")
}
Hereโ€™s model class ๐Ÿ‘‡
Copy code
package model

import kotlinx.serialization.Serializable

@Serializable
data class AllEmojiItem(
    val aliases: List<String>,
    val category: String,
    val description: String,
    val emoji: String,
    val ios_version: String,
    val skin_tones: Boolean,
    val tags: List<String>,
    val unicode_version: String
)
j
you have a list of objects, not an object
v
But it should then complain that there is
[
instead of
{
, not
EOF
, shouldn't it?
๐Ÿ‘Œ 3