private void getOrCreateReusableObjectComponent()

in johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/SchemaProcessor.java [197:267]


    private void getOrCreateReusableObjectComponent(final Class<?> from, final Schema schema,
                                                    final Cache cache,
                                                    final ReflectionValueExtractor reflectionValueExtractor,
                                                    final Instance instance) {
        schema.setType(Schema.SchemaType.object);
        final String ref = cache.findRef(from);
        if (ref != null) {
            schema.setRef(ref);
            cache.initDefinitions(from);
            return;
        } else if (Object.class == from) {
            schema.setProperties(new TreeMap<>());
            return;
        }
        if (setClassAsTitle) {
            schema.setTitle(from.getName());
        }

        final BiPredicate<Type, String> ignored = createIgnorePredicate(from);

        cache.onClass(from);
        schema.setProperties(new TreeMap<>());
        Class<?> current = from;
        while (current != null && current != Object.class) {
            final Map<String, String> fields = Stream.of(current.getDeclaredFields())
                    .filter(it -> isVisible(it, it.getModifiers()))
                    .peek(f -> {
                        if (Modifier.isFinal(f.getModifiers())) {
                            handleRequired(schema, () -> findFieldName(f));
                        }
                    })
                    .peek(f -> {
                        final String fieldName = findFieldName(f);
                        if (!ignored.test(f.getGenericType(), fieldName)) {
                            final Instance fieldInstance;
                            if (reflectionValueExtractor != null) {
                                fieldInstance = reflectionValueExtractor.createDemoInstance(
                                        instance == null ? null : instance.value, f);
                            } else {
                                fieldInstance = null;
                            }
                            final Schema value = doMapSchemaFromClass(resolveType(f.getGenericType(), from), cache, reflectionValueExtractor, fieldInstance);
                            fillMeta(f, value);
                            if (fieldInstance != null && !fieldInstance.isCreated()) {
                                switch (value.getType()) {
                                    case array:
                                    case object:
                                        break;
                                    default:
                                        value.setDefaultValue(fieldInstance.value);
                                }
                            }
                            schema.getProperties().put(fieldName, value);
                        } else {
                            onIgnored(schema, f, cache);
                        }
                    }).collect(toMap(Field::getName, this::findFieldName));
            Stream.of(current.getDeclaredMethods())
                    .filter(it -> isVisible(it, it.getModifiers()))
                    .filter(it -> (it.getName().startsWith("get") || it.getName().startsWith("is")) && it.getName().length() > 2)
                    .forEach(m -> {
                        final String methodName = findMethodName(m);
                        final String key = fields.getOrDefault(methodName, methodName); // ensure we respect jsonbproperty on fields
                        if (!ignored.test(resolveType(m.getGenericReturnType(), from), key) && !schema.getProperties().containsKey(key)) {
                            schema.getProperties().put(key, doMapSchemaFromClass(m.getGenericReturnType(), cache, null, null));
                        }
                    });
            current = current.getSuperclass();
        }
        cache.onSchemaCreated(from, schema);
    }