save() cant cast string to long
Hey! im trying to save data in JSONModel. Ex: JSONObject object = new JSONObject(json); json_model.setData(object); save(false); and im getting exception Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
on saving my id field! in json i have it like {"final_product_audit_id":200}
i tried: Timber.e("id: " + object.getLong("final_product_audit_id")); and its passed! but this one: Timber.e("id: " + (long)object.get("final_product_audit_id")); failed.
on line: ((long)modelContainer.getValue("final_product_audit_id")) > 0 i got the exception
Thank you!
It appears the JSONObject.get(object) is the culprit. So it appears its attempting to retrieve a field which the JSON thinks is an Integer then trying to unbox into a long.
Either: 1. subclass JsonModel use that instead and return the proper value from the JSONObject so it can cast properly (not ideal, but works) 2. Don't use ModelContainer and just parse into a Model first (even less ideal).
ok, so i extended JSONModel and Overrided getValue() and for id column of table it works perfectly, but for foreign keys...when bindToContentValues called they (fk) using own container so getValue() is called not from JsonModel but from BaseModelContainer. Any help? Thanks!
ok i Overrided getInstance also...now i only work with JsonModel class and getValue() is called properly. Thanks anyway :)
Your'e welcome. Its meant for simple cases and may benefit people. Right now its not meant to be a full parsing library inside of an ORM database library. Its possible I can add a separate hook to smooth over the conversions.