How can I store the HashMap <String, String>?
1 answer
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.
+4
source to share