I am trying to convert a list of records to some Java object (so, ActiveJDBC Model to another Java class), but I want to be able to call the same method for all my models and pass the Model type, something like:
private <M extends Model, T> List<T> getObjects(Class<M> modelType, Class<T> objectType) {
List<T> records = new ArrayList<T>();
M.findWith(new ModelListener<M>() {
public void onModel(M row) {
// Here I would convert the Model to my desired object and add it to the list of records
}
}, null);
return records.isEmpty() ? null : records;
}
Which I would call like:
getObjects(MyModel.class, MyObject.class);
I get
Exception: failed to determine Model class name, are you sure models have been instrumented?
on M.findWith(...)
Any idea how to make it work?
Thanks!