sqlite - Unable to serialize custom object activeandroid -
i trying store custom object blob in sqllite db. object field of class extending model. other fields (of primitive types) go in db, custom 1 - null always.
@table(name = "data") public class data extends model { @column(name = "number") private int number; @column(name = "blob") private contact blob; ...
this how store entity
data data = new data(0, new contact(id, name, number)); data.save();
here contact class
public class contact { private string id; private string name; private string number; ...
i believe typeserializer needed, i've created one.
public class contactserializer extends typeserializer { private static final string elements_delimiter = ";"; @override public object deserialize(object asstring) { string[] aftersplit = ((string) asstring).split(elements_delimiter); return new contact(aftersplit[0], aftersplit[1], aftersplit[2]); } @override public class<?> getdeserializedtype() { return contact.class; } @override public serializedtype getserializedtype() { return serializedtype.string; } @override public object serialize(object ascontact) { contact temp = (contact) ascontact; return temp.getid() + elements_delimiter + temp.getname() + elements_delimiter + temp.getnumber(); }
}
when query db got object particular field "contact" null always. might problem? need specify typeserializer object? or implementation of typeserializer i've created wrong?
you need extent contact model:
@table(name = "contact") public class contact extends model{ @column(name = "id") private string id; @column(name = "name") private string name; @column(name = "number") private string number; }
now should work out of box. it's bit late response perhaps else.
Comments
Post a Comment