question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to decode RealmList from primitive array

See original GitHub issue

I’d like to store an array of primitives in my Realm object, so I am declaring it like:

@Serializable
class Some: RealmObject {

    @PrimaryKey
    var id: String = uuid4().toString()

    private var list: RealmList<Int> = realmListOf()

}

When trying to decode it from the server response I get Expected class kotlinx.serialization.json.JsonObject as the serialized body of kotlinx.serialization.Polymorphic<RealmList>, but had class kotlinx.serialization.json.JsonArray, which is gone in case I mark this list property as @Transient.

I am using Ktor with Json serializer:

val httpClient = HttpClient {
    expectSuccess = true
    install(ContentNegotiation) {
        json(Json {
            ignoreUnknownKeys = true
            encodeDefaults = true
            prettyPrint = true
        })
    }
    install(HttpTimeout) {
        requestTimeoutMillis = 15000
    }
}

Am I missing something? Or RealmList needs a custom serializer to be specified for the class which is using it?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
grigorevpcommented, Jul 7, 2022

Yeah, thanks! Just wanted to check if I’m not missing some built-in solution

0reactions
rorbechcommented, Sep 26, 2022

Closing due to lack of feedback. @grigorevp If you still need assistance with this please let us know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gson deserialization for Realm list of primitives - Stack Overflow
I am using realm with gson. I have a modal which has a list of int type field. Realm does not support currently...
Read more >
Convert an Array of Primitives to a List | Baeldung
In this short tutorial, we'll show how to convert an array of primitives to a List of objects of the corresponding type.
Read more >
Realm: Create reactive mobile apps in a fraction of the time
If you add it to other field types, compilation will fail. Fields with primitive types and the RealmList type are required implicitly.
Read more >
Groovy Language Documentation
Any indentation would yield a compilation error. ... 4, Assert that we created an array of primitive ints ...
Read more >
Arrays - Learning the Java Language
class ArrayDemo { public static void main(String[] args) { // declares an array ... the compiler prints an error like the following, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found