Skip to content

Tag: reflection

Casting to array type using reflection

I find myself in a situation where it seems I would need to be able to cast an Object that is an array of some other, non-primitive type, into its concrete array type, to pass to a generic. The same thing is trivial to get to work with non-array types: desiredType.cast(o) yields an object of the correct type. Would someone

JSONPath resolver for Java objects

How can I get a value from an Java object instead from a JSON string by applying a JSONPath expression? I receive a Java object that is created from a JSON string (via Jackson, no way to influence it): I further have some JSONPath expressions as Java Strings reflecting values in the object (they might be much more complex): I

Reflection generic get field value

I am trying to obtain a field’s value via reflection. The problem is I don’t know the field’s type and have to decide it while getting the value. This code results with this exception: Can not set …

Simple way to get wrapper class type in Java

I have a piece of code where I need to pass the class of a field in a method. Because of the mechanics of my code I can only handle reference objects and not primitives. I want an easy way of determining if a Field’s type is primitive and swap it with the appropriate wrapper class. So in code what