Package org.apache.juneau.objecttools
Class ObjectIntrospector
java.lang.Object
org.apache.juneau.objecttools.ObjectIntrospector
POJO method introspector.
This class is used to invoke methods on Objects using arguments in serialized form.
Example:
String
The arguments passed to the identified method are POJOs serialized in JSON format. Arbitrarily complex arguments can be passed in as arguments.
- This is an extremely powerful but potentially dangerous tool. Use wisely.
-
Constructor Summary
ConstructorsConstructorDescriptionShortcut for callingnew ObjectIntrospector(o,null );ObjectIntrospector(Object object, ReaderParser parser) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectIntrospectorStatic creator.static ObjectIntrospectorcreate(Object o, ReaderParser parser) Static creator.<T> TinvokeMethod(Class<T> returnType, Method method, Reader args) Primary method.<T> TinvokeMethod(Class<T> returnType, String method, String args) Convenience method for invoking argument from method signature (@seeMethodInfo.getSignature().invokeMethod(Method method, Reader args) Primary method.invokeMethod(String method, String args) Convenience method for invoking argument from method signature (@seeMethodInfo.getSignature().
-
Constructor Details
-
ObjectIntrospector
Shortcut for callingnew ObjectIntrospector(o,null );- Parameters:
o- The object on which Java methods will be invoked.
-
ObjectIntrospector
Constructor.- Parameters:
object- The object on which Java methods will be invoked.parser- The parser to use to parse the method arguments. Ifnull ,JsonParser.DEFAULTis used.
-
-
Method Details
-
create
Static creator.- Parameters:
o- The object on which Java methods will be invoked.- Returns:
- A new
ObjectIntrospectorobject.
-
create
Static creator.- Parameters:
o- The object on which Java methods will be invoked.parser- The parser to use to parse the method arguments.- Returns:
- A new
ObjectIntrospectorobject.
-
invokeMethod
public <T> T invokeMethod(Class<T> returnType, Method method, Reader args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, ParseException, IOException Primary method.Invokes the specified method on this bean.
- Type Parameters:
T- The return type of the method call.- Parameters:
returnType- The return type of the method call.method- The method being invoked.args- The arguments to pass as parameters to the method. These will automatically be converted to the appropriate object type if possible. Can benull if method has no arguments.- Returns:
- The object returned by the call to the method, or
null if target object isnull . - Throws:
IllegalAccessException- If theConstructor object enforces Java language access control and the underlying constructor is inaccessible.IllegalArgumentException- If one of the following occurs:- The number of actual and formal parameters differ.
- An unwrapping conversion for primitive arguments fails.
- A parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion.
- The constructor pertains to an enum type.
InvocationTargetException- If the underlying constructor throws an exception.ParseException- Malformed input encountered.IOException- Thrown by underlying stream.
-
invokeMethod
public <T> T invokeMethod(Class<T> returnType, String method, String args) throws NoSuchMethodException, IllegalArgumentException, InvocationTargetException, IllegalAccessException, ParseException, IOException Convenience method for invoking argument from method signature (@seeMethodInfo.getSignature().- Type Parameters:
T- The return type of the method call.- Parameters:
returnType- The return type of the method call.method- The method being invoked.args- The arguments to pass as parameters to the method. These will automatically be converted to the appropriate object type if possible. Can benull if method has no arguments.- Returns:
- The object returned by the call to the method, or
null if target object isnull . - Throws:
NoSuchMethodException- If method does not exist.IllegalAccessException- If theConstructor object enforces Java language access control and the underlying constructor is inaccessible.IllegalArgumentException- If one of the following occurs:- The number of actual and formal parameters differ.
- An unwrapping conversion for primitive arguments fails.
- A parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion.
- The constructor pertains to an enum type.
InvocationTargetException- If the underlying constructor throws an exception.ParseException- Malformed input encountered.IOException- Thrown by underlying stream.
-
invokeMethod
public Object invokeMethod(Method method, Reader args) throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, ParseException, IOException Primary method.Invokes the specified method on this bean.
- Parameters:
method- The method being invoked.args- The arguments to pass as parameters to the method. These will automatically be converted to the appropriate object type if possible. Can benull if method has no arguments.- Returns:
- The object returned by the call to the method, or
null if target object isnull . - Throws:
IllegalAccessException- If theConstructor object enforces Java language access control and the underlying constructor is inaccessible.IllegalArgumentException- If one of the following occurs:- The number of actual and formal parameters differ.
- An unwrapping conversion for primitive arguments fails.
- A parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion.
- The constructor pertains to an enum type.
InvocationTargetException- If the underlying constructor throws an exception.ParseException- Malformed input encountered.IOException- Thrown by underlying stream.
-
invokeMethod
public Object invokeMethod(String method, String args) throws NoSuchMethodException, IllegalArgumentException, InvocationTargetException, IllegalAccessException, ParseException, IOException Convenience method for invoking argument from method signature (@seeMethodInfo.getSignature().- Parameters:
method- The method being invoked.args- The arguments to pass as parameters to the method. These will automatically be converted to the appropriate object type if possible. Can benull if method has no arguments.- Returns:
- The object returned by the call to the method, or
null if target object isnull . - Throws:
NoSuchMethodException- If method does not exist.IllegalAccessException- If theConstructor object enforces Java language access control and the underlying constructor is inaccessible.IllegalArgumentException- If one of the following occurs:- The number of actual and formal parameters differ.
- An unwrapping conversion for primitive arguments fails.
- A parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion.
- The constructor pertains to an enum type.
InvocationTargetException- If the underlying constructor throws an exception.ParseException- Malformed input encountered.IOException- Thrown by underlying stream.
-