android ormlite - storing string array

android, arrays, ormlite, string

Solution

First you make the class Serializable. You can optionally add the table name at the top of the class by annotation.

then for the variables you have to add the database field annotation. In case of the string array you also have to annotate it as a Serializable datatype. You will get something like this:

@DatabaseTable(tableName = "A")
Class A implements Serializable{

    @DatabaseField
    int age

    @DatabaseField(dataType = DataType.SERIALIZABLE)
    String[] childrenNames = new String[2];
}

Also dont forget to create getters and setters for each of the variables.

Problem

I want to persist a class which contain String array. How to do it in ormlite? For example, ``` class A { int age; String[] childrenNames = new String[2]; } ```

Original source