mardi 14 août 2018

ReflectionUtils how to replace deprecated methods?

Many methods in the org.springframework.util.ReflectionUtils package have been deprecated, but there is no hint which methods should be used as a replacement. How are the following methods to be replaced properly?

org.springframework.util.ReflectionUtils.makeAccessible();
org.springframework.util.ReflectionUtils.isAccessible();

My goal is to get all field names and save them into a Map. So far the following code worked, but how can I replace the deprecated methods?

ReflectionUtils.doWithFields(object.getClass(), field -> {
            if (!field.isAccessible()) ReflectionUtils.makeAccessible(field);
            map.put(field.getName(), ReflectionUtils.getField(field, object));
        });





Aucun commentaire:

Enregistrer un commentaire