0

the sever is sending me an array of arrays of bytes [[Byte]] or List<List<Byte>>. A small sample looks like this [[102, 222, 111], [92, 22, 111], [142, 122, 32]] when writing this into a file, we get an executable, don't mean to compare with iOS but there I simnply do something like let data = Data(bytes) and then data.write(to: "path/file.jpg"). I can't get far as right when my application receives the JSON with the bytes and tried to deserialize it into:

import kotlinx.serialization.Serializable

@Serializable
data class ServerResponse(
    val fileRaw: List<List<Byte>>?
)

The application with the following error --> Unexpected JSON token at offset 1829: Failed to parse 'byte'

I know I will still have some troubleshooting after solving this, like actually writing this into an executable, but that is outside of the scope of this question.

How can I receive and serially an array of arrays of bytes (VISUALLY [[Byte]] or List<List<Byte>>)?

WiseEye
  • 133
  • 9
  • Make you response type generic Response type only not byte only like Response of retrfoit. When you do response.body() it will give you the byte array – ahjo4321hsotuhsa Oct 12 '22 at 04:02
  • I think you need to describe things a bit more clearly. You talk about JSON, but nothing here parses JSON. Serializable is not the same as JSON serialization. And I see nothing here that's making a server request, so you gave us only a small portion of the relevant code. – Gabe Sechan Oct 12 '22 at 04:44
  • @GabeSechan hey! So, Serializable from Kotlinx parses JSON, maybe you got it confused with another library? The server requests is simple, really just a @GET(https://server.com/my_scenario) so I did not think it would be relevant to add that. – WiseEye Oct 12 '22 at 05:23

0 Answers0