I work with Realm for Android, I had to work with a map repository. However, Realm does not support maps, so I made a workaround for this, as suggested here
But when I serialize the data stored in JSON, the output goes beyond what is expected.
Expected JSON:
{
"key1": "value1",
"key2": "value2",
"key3": "value3",
"key4": "value4"
}
And what I get:
[{
"key": "key1",
"value": "value1"
},
{
"key": "key2",
"value": "value2"
},
{
"key": "key3",
"value": "value3"
}]
My code is:
public class ActivityDetails extends RealmObject {
public RealmList<KeyValueStore> map;
public String bid;
public String s;
}
public class KeyValueStore extends RealmObject {
private String key;
private String value;
public void setKey(String key) {
this.key = key;
}
public void setValue(String value) {
this.value = value;
}
}
Is there a way to serialize a map as data as expected?
Edit: the following is the complete object, which is my data (as expected)
{
"s": "someValue",
"bid": "someValue",
"map": [
{
"key": "key1",
"value": "value1"
},
{
"key": "key2",
"value": "value2"
},
{
"key": "key3",
"value": "value3"
}
]
}