0

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!

Maxime Laval
  • 4,068
  • 8
  • 40
  • 60

1 Answers1

1

you need to instrument models before you use them. Please, see http://javalite.io/instrumentation

ipolevoy
  • 5,432
  • 2
  • 31
  • 46
  • I do (works for the rest of my code). I think it's because the way generics work, M.findWith(...) uses the Model class and not my class extending it (MyModel.java) and the fact that findWith() is static doesn't help... – Maxime Laval Sep 16 '15 at 20:53