I have a class:
@Table(name = "Control")
public class Control extends Model{
@Column
private String name;
[...]
@Column
private Map<String, Object> properties;
}
I have other fields in this class, but i wrote here only those which is enough to show what is my problem.
I got an exception about insertion:
09-14 22:11:34.542: E/SQLiteLog(11482): (1) table Control has no column named properties
Object can be either String[] or String.
If I dont place @Column on HashMap data, than everything works "fine" only the problem they are not stored.
So my question is how should I solve storing this hashmap.
My data comes from API, and it has not the same properties always:
controls: [
{
bundle: "CloseButton",
frame: "0,0,25,25"
},
{
referenceKey: "AccelerationGyro",
name: "Acceleration Sensor",
bundle: "Gyro",
properties: {
axis: "Z"
observedKey: "brakeState",
requiedValue: "1"
},
channels: {
CH: "Acceleration"
}
},
{
referenceKey: "SteeringGyro",
name: "Steering Sensor",
bundle: "Gyro",
properties: {
axis: "Y"
allowedOnI: [
"@Lights",
"@Rack",
"@ReversingLamp"
],
},
channels: {
CH: "Steering"
}
},
I want to store this class with using ActiveAndroid lib. But unfortunatelly I could not find any solution to this on the web.
I'm not sure if my question is clear, I can provide additional stuff if needed. I just want to store the HashMap too. :P Is it maybe connected somehow to TypeSerializers?
Thanks your answer in advance.
ActiveAndroid don't persist
Map
type by default.Yes, you are right, you must write your own
TypeSerializer
, to serialize thisMap
as an String in some format (e.g: JSON) and deserialize the String to yourMap
.Maybe this code can help you to start this:
And register then as
<meta-data>
in your<Application>
.More information: https://github.com/pardom/ActiveAndroid/wiki/Type-serializers