private static Object invokeGetterMethod()

in aws-iot-device-sdk-java/src/main/java/com/amazonaws/services/iot/client/shadow/AwsIotJsonSerializer.java [53:80]


    private static Object invokeGetterMethod(Object target, Field field) throws IOException {
        String fieldName = Character.toUpperCase(field.getName().charAt(0)) + field.getName().substring(1);
        String getter = "get" + fieldName;

        Method method;
        try {
            method = target.getClass().getMethod(getter);
        } catch (NoSuchMethodException | SecurityException e) {
            if (e instanceof NoSuchMethodException && boolean.class.equals(field.getType())) {
                getter = "is" + fieldName;
                try {
                    method = target.getClass().getMethod(getter);
                } catch (NoSuchMethodException | SecurityException ie) {
                    throw new IllegalArgumentException(ie);
                }
            } else {
                throw new IllegalArgumentException(e);
            }
        }

        Object value;
        try {
            value = method.invoke(target);
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            throw new IOException(e);
        }
        return value;
    }