Class ObjectIntrospector

java.lang.Object
org.apache.juneau.objecttools.ObjectIntrospector

public final class ObjectIntrospector extends Object
POJO method introspector.

This class is used to invoke methods on Objects using arguments in serialized form.

Example:

String string1 = "foobar"; String string2 = ObjectIntrospector .create(string) .invoke(String.class, "substring(int,int)", "[3,6]"); // "bar"

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.
See Also:
  • Constructor Details

    • ObjectIntrospector

      public ObjectIntrospector(Object object, ReaderParser parser)
      Constructor.
      Parameters:
      object - The object on which Java methods will be invoked.
      parser - The parser to use to parse the method arguments. If null, JsonParser.DEFAULT is used.
    • ObjectIntrospector

      Shortcut for calling new ObjectIntrospector(o, null);
      Parameters:
      o - The object on which Java methods will be invoked.
  • Method Details

    • create

      public static ObjectIntrospector create(Object o)
      Static creator.
      Parameters:
      o - The object on which Java methods will be invoked.
      Returns:
      A new ObjectIntrospector object.
    • create

      public static ObjectIntrospector create(Object o, ReaderParser parser)
      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 ObjectIntrospector object.
    • invokeMethod

      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 be null if method has no arguments.
      Returns:
      The object returned by the call to the method, or null if target object is null.
      Throws:
      IllegalAccessException - If the Constructor 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

      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 be null if method has no arguments.
      Returns:
      The object returned by the call to the method, or null if target object is null.
      Throws:
      IllegalAccessException - If the Constructor 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

      Convenience method for invoking argument from method signature (@see MethodInfo.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 be null if method has no arguments.
      Returns:
      The object returned by the call to the method, or null if target object is null.
      Throws:
      NoSuchMethodException - If method does not exist.
      IllegalAccessException - If the Constructor 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

      Convenience method for invoking argument from method signature (@see MethodInfo.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 be null if method has no arguments.
      Returns:
      The object returned by the call to the method, or null if target object is null.
      Throws:
      NoSuchMethodException - If method does not exist.
      IllegalAccessException - If the Constructor 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.