private Object tryCreatingObjectInstance()

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


        private Object tryCreatingObjectInstance(final Type javaType) {
            final Class<?> type = Class.class.cast(javaType);
            if (type.isPrimitive()) {
                if (int.class == type) {
                    return 0;
                }
                if (long.class == type) {
                    return 0L;
                }
                if (double.class == type) {
                    return 0.;
                }
                if (float.class == type) {
                    return 0f;
                }
                if (short.class == type) {
                    return (short) 0;
                }
                if (byte.class == type) {
                    return (byte) 0;
                }
                if (boolean.class == type) {
                    return false;
                }
                throw new IllegalArgumentException("Not a primitive: " + type);
            }
            if (Integer.class == type) {
                return 0;
            }
            if (Long.class == type) {
                return 0L;
            }
            if (Double.class == type) {
                return 0.;
            }
            if (Float.class == type) {
                return 0f;
            }
            if (Short.class == type) {
                return (short) 0;
            }
            if (Byte.class == type) {
                return (byte) 0;
            }
            if (Boolean.class == type) {
                return false;
            }
            if (type.getName().startsWith("java.")
                || type.getName().startsWith("javax.")
                || type.getName().startsWith("jakarta.")
            ) {
                return null;
            }
            try {
                return type.getConstructor().newInstance();
            } catch (final NoSuchMethodException | InstantiationException | IllegalAccessException
                    | InvocationTargetException e) {
                // no-op, ignore defaults there
            }
            return null;
        }