Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling JsonSchemaConfig.builder() scans the entire classpath #182

Open
stellalie opened this issue May 24, 2023 · 0 comments
Open

Calling JsonSchemaConfig.builder() scans the entire classpath #182

stellalie opened this issue May 24, 2023 · 0 comments

Comments

@stellalie
Copy link

stellalie commented May 24, 2023

This is because calling JsonSchemaConfig.builder() automatically sets the SubclassesResolver(null) and which in turn trigger the entire classpath scan to build class graph, such

public SubclassesResolver(ClassGraph classGraph) {
        if (classGraph == null) {
            log.debug("Entire classpath will be scanned because SubclassesResolver is not configured. See https://github.com/mbknor/mbknor-jackson-jsonSchema#subclass-resolving-using-reflection");
            classGraph = new ClassGraph();
        }

        this.scanResult = classGraph.enableClassInfo().scan();
    }

This is prob the side effect on generated code from scala to java - but I haven't dig deeper

This takes up a lot of memory and is a waste of resources esp. if we are specifying the packages/classes to scan. In the code below, we are already scanning the entire classpath at JsonSchemaConfig.builder() before setting limiting the packages to scan subclassesResolver(..) e.g

    val config = JsonSchemaConfig.builder()
        .subclassesResolver(SubclassesResolver(listOf(ENTITY_PACKAGES_TO_SCAN), listOf()))
         .....
        .build()```
@stellalie stellalie changed the title Calling JsonSchemaConfig.builder() scan the entire classpath Calling JsonSchemaConfig.builder() scans the entire classpath May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant