Reputation: 1
I have an API application in Spring which receives input as an Object array. The composition of this array is controlled based on the API I invoke. Each API has a different and specific request object.
For each API call, I need to invoke an audit operation. But this should be done ONLY if a certain value exists in each request I receive. The value that I need to look for could be different for each API call.
How can I write a generic config using Spring that will dynamically check the presence of my pre-requisite value? The value I look for is a property in a Bean. The type of Bean differs with each API call
Upvotes: 0
Views: 2766
Reputation: 8334
I think you should use reflection to get the value.
Class aClass = MyObject.class Field field = aClass.getField("someField");
MyObject objectInstance = new MyObject();
Object value = field.get(objectInstance);
Here is a tutorial
http://tutorials.jenkov.com/java-reflection/fields.html
Upvotes: 1