public Map doFindReaders()

in johnzon-mapper/src/main/java/org/apache/johnzon/mapper/access/MethodAccessMode.java [51:82]


    public Map<String, Reader> doFindReaders(final Class<?> clazz) {
        final Map<String, Reader> readers = new HashMap<>();
        if (isRecord(clazz) || Meta.getAnnotation(clazz, JohnzonRecord.class) != null) {
            readers.putAll(Stream.of(clazz.getMethods())
                .filter(it -> it.getDeclaringClass() != Object.class && it.getParameterCount() == 0)
                .filter(it -> !"toString".equals(it.getName()) && !"hashCode".equals(it.getName()))
                .filter(it -> !isIgnored(it.getName()) && Meta.getAnnotation(it, JohnzonAny.class) == null)
                .collect(toMap(m -> extractKey(m.getName(), m, null), it -> new MethodReader(it, it.getGenericReturnType()))));
        } else {
            final PropertyDescriptor[] propertyDescriptors = getPropertyDescriptors(clazz);
            for (final PropertyDescriptor descriptor : propertyDescriptors) {
                final Method readMethod = descriptor.getReadMethod();
                final String name = descriptor.getName();
                if (readMethod != null && readMethod.getDeclaringClass() != Object.class) {
                    if (isIgnored(name) || Meta.getAnnotation(readMethod, JohnzonAny.class) != null) {
                        continue;
                    }
                    readers.put(extractKey(name, readMethod, null), new MethodReader(readMethod, readMethod.getGenericReturnType()));
                } else if (readMethod == null && descriptor.getWriteMethod() != null && // isXXX, not supported by javabeans
                        (descriptor.getPropertyType() == Boolean.class || descriptor.getPropertyType() == boolean.class)) {
                    try {
                        final Method method = clazz.getMethod(
                                "is" + Character.toUpperCase(name.charAt(0)) + (name.length() > 1 ? name.substring(1) : ""));
                        readers.put(extractKey(name, method, null), new MethodReader(method, method.getGenericReturnType()));
                    } catch (final NoSuchMethodException e) {
                        // no-op
                    }
                }
            }
        }
        return readers;
    }