Image

Imageilja_l wrote in Imagejava_dev

reflection API

UPDATE:
Sorry, my mistake, mistyped function. Anyway, field.get(field.getType()) works just fine.
/UPDATE

I wonder how one would solve this problem:
I have a serialized object and I want to retrieve all the fields of the object and their values.

Now a logical way to do that would be something like that:

Object o; // deserialized object
Field[] fa = o.getClass().getFields();

// -- DOESN'T EXIST! --
fa[somenumber].getValue();
// --------------------

It is possible to get the type of the field. And there is a super user-friendly function Field.get (Object o) that assignes the "o" the value of the field (wraps if o is a primitive). It could be a solution to use field.get(field.getType()), but if the value is a primitive I don't see a normal workaround.

Help, anyone?