v79
12/28/2023, 6:03 PM@Serializable
class ImageDTO(val srcKey: String, val contentType: String, val bytes: String)
I get the following error:
Could not deserialize body. Error is: Invalid symbol ':'(72) at index 4
The source JSON object looks like this:
{"srcKey":"piCture.jpg","contentType":"image/jpeg","bytes":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD.......
So it looks like deserialization is being tripped up by the "bytes":"data:image..."
part. Any suggestions? Perhaps I shouldn't be trying to upload images as a base64-encoded string?Adam S
12/28/2023, 7:20 PMimport kotlinx.serialization.*
import kotlinx.serialization.json.*
fun main() {
val data = """
{"srcKey":"piCture.jpg","contentType":"image/jpeg","bytes":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD"}
""".trimIndent()
val i: ImageDTO = Json.decodeFromString(data)
println(i)
}
@Serializable
data class ImageDTO(val srcKey: String, val contentType: String, val bytes: String)
ImageDTO(srcKey=piCture.jpg, contentType=image/jpeg, bytes=data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD)
v79
12/28/2023, 8:11 PMv79
12/28/2023, 8:42 PMv79
12/28/2023, 9:03 PMdata:image/jpeg;base64,
then the deserialization actually works.v79
12/29/2023, 8:33 AMv79
12/29/2023, 10:14 AM