https://kotlinlang.org logo
Title
h

hetang

07/10/2017, 5:59 PM
I think you need to write wrapper to convert your List<List<string>> to realm objects
v

vivekneel

07/10/2017, 6:32 PM
hetang: Thanks! 1- Realm does not work with generics , gives null pointer, and i can’t say var xyz : RealmList , it needs a type parameter 2 - My response is not ArrayList<ArrayList<String>> , It’s ArrayList<ArrayList> using the second solution , gives parse exception. This is the part of the response :
seats: [
[
"Third Class",
[
"S18"
]
]
]
h

hetang

07/10/2017, 6:34 PM
@vivek for 1. Please take a closer look at my example. I have
var xyz: RealmList<B>
. It means B is Realm model 2. From your example I see you have ArrayList<ArrayList<String>>
v

vivekneel

07/10/2017, 6:44 PM
@hetang : Yep. I tried the first solution.
data class RealmListWrapper<B : RealmObject>(
        var xyz: RealmList<B>
) : RealmObject()
It gave
Error:Execution failed for task ':app:compileJusticketsDebugJavaWithJavac'.
> java.lang.NullPointerException
, some issue with realm using generics 2. Oh, i am little bit confused. I was having like this for so long
@SerializedName("seats")
    private ArrayList<ArrayList> seats;
Now am trying to get this converted to realm object class And parse successfully. This is how i declared it
private RealmList<RealmListWrapper> seats;
where realmlistwrapper is an wrapper for
string
, unfortunatley it did not work.
h

hetang

07/10/2017, 6:45 PM
i think you getting confused between API object and Realm object
you needs to create both as different object
let you GSON parse as normal object
then you convert your API object to Realm object
you do not need to have RealmObject as API model
👍 1
v

vivekneel

07/14/2017, 5:01 PM
Hi @hetang! I have solved this issue. I serialized ArrayList of ArrayList which gives Json as string which is then stored in dB.
h

hetang

07/14/2017, 5:08 PM
Good to hear that but its has its own pros and cons. Doing this you can’t filter value in realm query, you need to do conversion of string to json and application needs to do filter. Its upto you, I feel this sort of hack to store value rather using realm to its potential
👍 1