I apologize if I\'m not super clear with my explanation but I\'ll add to and edit this question for clarity if requested.
I am developing an Android app which receives d
Is this a good plan or should I write two completely separate ways of extracting the Image URL from the data, NOT converting the object from ForeignCollection to ArrayList?
It should work. I don't see an easy way to do it otherwise.
Some points:
ForeignCollection
as transient so it is ignored when transferring over JSON? Then you can use the same User
object for both JSON and ORMLite.hydrate()
method would be good so it would convert from media
-> mediaCollection
and vice versa.If it is a good plan, how do I convert a ForeignCollection to an ArrayList?
This is easier. A ForeignCollection
is a Collection
. You can just do a:
media = new ArrayList<Image>(mediaCollection);
So your User.getMedia()
method should check for null
and if so, convert from the mediaCollection
field.
You can't create a ForeignCollection other than first storing the objects in the database, then have ormlite retrieve them in the ForeignCollection. You can use a Collection instead of a ForeignCollection, but it works the same way. What I do is the following: I have two collections in the parent class. One is an ArrayList that the json or xml is deserialized into. When the parent object gets stored, the dao stores the objects in the Arraylist to the database, in the table that's linked to the other Collection, a ForeignCollection. When the parent object is retrieved, it automatically contains the objects in the ForeignCollection. It's not perfect, but it works.
Just to Convert from @ForeignCollectionField
to ArrayList<Object>
you can do that:
ArrayList<Object> taskFieldsList = new ArrayList<Object>(your collection);
hope it's help you.