Hello, I'm getting error `Unexpected JSON token at...
# serialization
y
Hello, I'm getting error
Unexpected JSON token at offset 11023: Expected start of the object '{', but had ':' instead
JSON input: .....","type":"BLOGPOST","category":"e054042e-bc50-4743-a6f5-94d9.....
and I'm not sure why
my content class
Copy code
@Entity(tableName = POST_TABLE)
@Serializable
data class Content(
    @PrimaryKey(autoGenerate = false) @SerialName("id") val postId: String,
    val body: String,
    @Transient var categoryId: String? = null,
    val createdOn: LocalDateTime,
    val hasBeenUpdated: Boolean,
    val header: String,
    val postLanguage: String,
    val postSlug: String,
    val postTitle: String,
    val status: String,
    val summary: String,
    val type: String,
    val updatedOn: LocalDateTime,
    val visits: Int,
) {
    @Ignore
    val category: Category?=null
    @Ignore
    var subcategories: List<Subcategory>? = null
}
and category
Copy code
@Entity(tableName = CATEGORY_TABLE)
@Serializable
data class Category(
    @PrimaryKey(autoGenerate = false) @SerialName("id") val categoryId: String,
    val categorySlug: String,
    val categoryTitle: String
)
I'm not facing an issue with subcategories only the category class
this is the actual json in postman
Copy code
"createdOn": "2022-02-06T16:17:08.16067","updatedOn": "2022-02-06T16:17:08.16067",
"status": "PUBLISHED",
"type": "BLOGPOST",
"category": {
   "id": "08e5788d-bc26-45a4-88fc-918ec5f7d8e9",
    "categoryTitle": "Meta",
     "categorySlug": "meta"
            },
"subcategories": [],
e
your exception shows
"category":"
, not
"category": {
as in your example
y
right, i don't understand why it's reading it like that when in postman it's correct
e
well try intercepting the request to see what you're actually getting
y
I have been trying to do that and can't figure it out 😅 I'm kinda new. I'll figure out how to intercept it and come back with the actual problem I guess. Thanks for answering!
yup it's getting it correctly too
e
it may be correct in one part of your input but not another? at least you should find where the substring in the exception occurs in your input
y
so the json is correct but the error happens when it tries so serialize it. What could cause it to come in correct and then go wrong to serialization?
r
Is it possible that it isn't serializing
category
correctly because it's in the body and not defined in the constructor?
469 Views