JSONModel Container
Hey! ok, i'm receiving json from server , setData() with it and after trying to convert it toModel(). (of course i'm using jsonmodel) how am i supposed to convert jsonmodel toModel() if my foreign key on .getInstance() from jsonmodel passing String? im getting cast error (JSONObject) inValue, can't cast string to json. What if i try convert to model with null foreign keys?? getting NPE even if in my model foreign keys can be null. Ideas? Any help would be appreciated.. Thanks!
ok, i had to override it... this is bad and i should feel bad but still...better then nothing!
public BaseModelContainer getInstance(Object inValue, Class columnClass) {
if(inValue != null && inValue.toString().equals("{}")){
return new JsonModel((JSONObject)inValue, columnClass);
}
if(columnClass.getSimpleName().equals("YourClassName")){
YourClassWithJsonModel.getJsonModel().load(inValue);
return new JsonModel((JSONObject)YourClassWithJsonModel.getJsonModel().getData(), columnClass);
}
}
This piece is meant not to be a Json parser and thus only handles get() from the JSONObject currently, which doesnt attempt to coerce the value to the proper column value. It's possible (and on my roadmap) to create a smarter db connector for JSON and generate code to interact in a much better way than the abstract/limited nature currently introduced by ModelContainer.
Hi,
Can you show how to use dbflow with json that has a 1-n relationship?
3.0.0+ has smarter value conversion for ModelContainer classes.