How can I store the HashMap <String, String>?
How do you store the HashMap in greenDAO and how do you create the corresponding objects?
I read the documentation twice back and forth, but nothing is there. Google didn't help either.
You have to create Entity with String-primary-key and String-proerty for value:
Entity mapEntity = schema.addEntity("Map");
mapEntity.addStringProperty("key").primaryKey();
mapEntity.addStringProperty("value");
Maybe some other attributes are needed for properties (depending on your needs) like unique, notNull.
If you want to keep your map inside an object, it is not that easy:
Basically you create an entity like this to hold all the Maps:
Entity mapEntity = schema.addEntity("Map");
mapEntity.addLongProperty("id").primaryKey().autoIncrement();
mapEntity.addStringProperty("key").unigue().notNull();
mapEntity.addStringProperty("value");
and then create a relationship toOne()
or toMany()
to link to the corresponding map.
PS Perhaps you should choose other names besides key
and value
. These variable names are commonly used and can create conflicts in greendao.