leadpony / justify

Justify is a JSON validator based on JSON Schema Specification and Jakarta JSON Processing API (JSON-P).
Apache License 2.0
96 stars 18 forks source link

javax.json.spi.JsonProvider conflict #27

Closed Generalus closed 5 years ago

Generalus commented 5 years ago

Hello!

We use justify library to validate json messages against draft-07 schema. Environment is Wildfly Application Server 12.

Justify works good, but Wildfly throws error while using security logic:

java.util.ServiceConfigurationError: javax.json.spi.JsonProvider: Provider org.glassfish.json.JsonProviderImpl not a subtype at java.util.ServiceLoader.fail(ServiceLoader.java:239) at java.util.ServiceLoader.access$300(ServiceLoader.java:185) at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376) at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) at java.util.ServiceLoader$1.next(ServiceLoader.java:480) at javax.json.spi.JsonProvider.provider(JsonProvider.java:90) at javax.json.Json.createReader(Json.java:220) at org.wildfly.security.auth.realm.token.validator.JwtValidator.extractClaims(JwtValidator.java:145) at org.wildfly.security.auth.realm.token.validator.JwtValidator.validate(JwtValidator.java:107) ...

Our build.gradle:

    compile 'org.leadpony.justify:justify:1.1.0'
    compile 'org.glassfish:jakarta.json:1.1.5:module'
    compileOnly group: 'javax.json', name: 'javax.json-api', version: '1.1.2' (registered as module in Wildfly)

if we change org.glassfish:jakarta.json:1.1.5:module to org.apache.johnzon:johnzon-core:1.1.12, we get the same error: java.util.ServiceConfigurationError: javax.json.spi.JsonProvider: Provider org.apache.johnzon.core.JsonProviderImpl not a subtype

We have made some experiments with different JSON provider implementations and got working solution with native Wildfly provider: org.glassfish.javax.json

Will be there any issues with org.glassfish.javax.json JSON provider (which is not described as recommended to use in your readme)? Or is there a way to connect your recomended providers with our Wildfly environment properly?

leadpony commented 5 years ago

Hello @Generalus

JSON-P develop team changed the Maven coordinates from version 1.1.5.

Version API Implementation
1.1.5 jakarta.json:jakarta.json-api org.glassfish:jakarta.json
Older javax.json:javax.json-api org.glassfish:javax.json

WildFly seems to provide javax.json:javax.json-api as its module. On the other hand, the classloader for your application loads jakarta.json:jakarta.json-api as a transitive dependency of org.glassfish:jakarta.json. Both jars have JsonProvider class and I believe the inconsistency between two different class code triggers the problem. Both Maven and Gradle cannot automatically select proper version because they have different coordinates.

Justify depends on jakarta.json:jakarta.json-api. If you stick to the API jar provided by WildFly, it may be safe to exclude the dependency in your build.gradle and use old org.glassfish:javax.json as the provider as you did. Also you can change the scope of the provider from compile to runtime.

Generalus commented 5 years ago

Thanks for help!

leadpony commented 5 years ago

I hope the problem is successfully solved.