Class ObjectIntrospector

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

public class ObjectIntrospector extends Object
POJO method introspector.

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

Security - secure by default:

As of Juneau 10.0, reflective method dispatch is denied by default. Before calling invokeMethod(...) (in any of its overloaded forms), the caller must explicitly allow-list the method(s) that may be invoked via allow(...) or allow(Predicate). Invoking a method that isn't allow-listed throws MethodNotAllowlistedException.

For trusted, in-process callers that need the pre-10.0 behavior of dispatching to any public, non-deprecated method, call allowAll() as a one-line migration. Never call allowAll() on an introspector whose method name/arguments are derived from an untrusted source (e.g. a REST request parameter) — allow-list the specific methods instead.

Example:

String string1 = "foobar"; String string2 = ObjectIntrospector .create(string1) .allow(String.class, "substring(int,int)") // Explicit allow-list. .invokeMethod(String.class, "substring(int,int)", "[3,6]"); // "bar"

For trusted, in-process-only use, allowAll() can be used instead of an explicit allow-list:

String string2 = ObjectIntrospector .create(string1) .allowAll() .invokeMethod(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.