Storing List of objects using DataType.SERIALIZABLE in ormlite android

android, ormlite

Solution

I've just changed the error message to be:

ORMLite does not know how to store class java.util.ArrayList for field 'items'. Use another class, custom persister, or to serialize it use dataType=DataType.SERIALIZABLE

Maybe that makes more sense? ORMLite is trying to say that it doesn't know how to store lists in a field. If you want to store collection of items then maybe you should take a look at the foreign-collection documentation.

Problem

How to save an ArrayList using ORMlite in android my model is as follows ``` class Model{ @DatabaseField public String type = ""; @DatabaseField public String name = ""; @DatabaseField public Date dateTime = null; @DatabaseField ArrayList<Item> items = null; } ``` And Item class has ``` class Item{ @DatabaseField String itemName; ... } ``` I am getting the following exception : ``` java.sql.SQLException: ORMLite can't store unknown class class java.util.ArrayList for field 'items'. Serializable fields must specify dataType=DataType.SERIALIZABLE ``` But when i specify my field as ``` @DatabaseField(dataType = DataType.SERIALIZABLE) ArrayList<Item> items = null; ``` The compiler gives a error called field cannot be resolved please help me with this.

Original source