Q:

GSON to Ormlite foreign collection

My model object has simple datatypes as well as other types of model objects
@SerializedName("account")
Account account;`

I serialize these model objects from a network api call using GSON.  GSON needs my model objects to be their respective types. I want to then write my model objects to a database using Ormlite and batch tasks, but Ormlite requires ForeignCollection<T> even if I only have one foreign object (instead of a list of foreign objects) in my model.
How do I get from one serialized element of T  into ForeignCollection<T> in my model file?
The real question of course is how to serialize and store models in my database which contain references to other models.

A:

It's not very clear what you are asking here, but maybe this can be useful:
assignEmptyForeignCollection
void assignEmptyForeignCollection(T parent,
                                  String fieldName)
                                  throws SQLException

Creates an empty collection and assigns it to the appropriate field in the parent object. This allows you to add things to the collection from the start. For example let's say you have an Account which has the field:
 @ForeignCollectionField(columnName = "orders")
 Collection<Order> orders;

You would then call: (In this case)
accoundDao.assignEmptyForeignCollection(account, "orders");
Order order1= new Gson().fromJson(someMethodThatCallsYourNetworkApi(),Order.class);

 // this would add it the collection and the internal DAO
 account.orders.add(order1);

