I think you need to write wrapper to convert your ...
# android
h
I think you need to write wrapper to convert your List<List<string>> to realm objects
v
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 :
Copy code
seats: [
[
"Third Class",
[
"S18"
]
]
]
h
@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
@hetang : Yep. I tried the first solution.
Copy code
data class RealmListWrapper<B : RealmObject>(
        var xyz: RealmList<B>
) : RealmObject()
It gave
Copy code
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
Copy code
@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
Copy code
private RealmList<RealmListWrapper> seats;
where realmlistwrapper is an wrapper for
string
, unfortunatley it did not work.
h
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
Hi @hetang! I have solved this issue. I serialized ArrayList of ArrayList which gives Json as string which is then stored in dB.
h
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