decentralized-identity / jsonld-common-java

Shared JSON-LD Java library.
Apache License 2.0
7 stars 6 forks source link

JsonLDObject default constructor depends on java.net.http.HttpClient #7

Closed vitorpamplona closed 8 months ago

vitorpamplona commented 2 years ago

I'd like to propose a clean up on the code to always create a JsonLdOptions with the currently used documentLoader passed as parameter JsonLdOptions(jsonldObject.documentLoader). The goal is to avoid calling SchemeRouter.defaultInstance() on JsonLdOptions's default constructor. That method has a direct dependency on java.net.http.HttpClient which doesn't exist on Android's Runtime.

This also speeds things up a bit for anyone using custom DocumentLoaders by never creating the default instance just to replace it with the custom one.

Here's an example. Android developers need to override this method, going from

        JsonLdOptions options = new JsonLdOptions();
        if (this.getDocumentLoader() != null) {
            options.setDocumentLoader(this.getDocumentLoader());
        }

to

        JsonLdOptions options = new JsonLdOptions(this.getDocumentLoader());

I actually don't know why this test exists: this.getDocumentLoader() != null, since the only way for the documentLoader to be null is if somebody manually set that to null, which seems weird.

peacekeeper commented 2 years ago

@vitorpamplona Sorry for late reponse.. This makes sense to me, do you want to create a PR to make that change?

peacekeeper commented 8 months ago

@vitorpamplona I think this should be fixed. Better late then never :)