Skip to content

Upgrading to com.networknt:json-schema-validator v2.0.0 breaks MockServer #1966

@peter-thomas-mgd

Description

@peter-thomas-mgd

Describe the issue
We have a Gradle project that has been using the MockServer Java client and server for a number of years in our unit tests. The project is in active development and we perform monthly maintenance to upgrade all dependencies to their latest versions.

The project has a dependency on com.networknt:json-schema-validator in its main code. When we upgraded json-schema-validator to version 2.0.0 and fixed the breaking changes in our main application, MockServer started failing with runtime errors in our tests. The main issue seems to be a change in the package namespaces and interfaces used by json-schema-validator .

What you are trying to do
In our Gradle configuration, we have the following dependencies:

implementation("com.networknt:json-schema-validator:2.0.0")
...
testImplementation("org.mock-server:mockserver-netty:5.15.0")

This configuration has worked in multiple previous versions of json-schema-validator up to version 1.5.9. But after the update to version 2.0.0 our tests fail with the following error:

java.lang.NoClassDefFoundError: com/networknt/schema/SpecVersion$VersionFlag
	at org.mockserver.validator.jsonschema.JsonSchemaValidator.<clinit>(JsonSchemaValidator.java:39) ~[mockserver-core-5.15.0.jar:5.15.0]
	at org.mockserver.serialization.ExpectationSerializer.getValidator(ExpectationSerializer.java:67) ~[mockserver-core-5.15.0.jar:5.15.0]
	at org.mockserver.serialization.ExpectationSerializer.deserialize(ExpectationSerializer.java:127) ~[mockserver-core-5.15.0.jar:5.15.0]
	at org.mockserver.serialization.ExpectationSerializer.deserializeArray(ExpectationSerializer.java:195) ~[mockserver-core-5.15.0.jar:5.15.0]
	at org.mockserver.serialization.ExpectationSerializer.deserializeArray(ExpectationSerializer.java:158) ~[mockserver-core-5.15.0.jar:5.15.0]
	at org.mockserver.mock.HttpState.handle(HttpState.java:600) ~[mockserver-core-5.15.0.jar:5.15.0]
	at org.mockserver.netty.HttpRequestHandler.channelRead0(HttpRequestHandler.java:114) ~[mockserver-netty-5.15.0.jar:5.15.0]
	at org.mockserver.netty.HttpRequestHandler.channelRead0(HttpRequestHandler.java:51) ~[mockserver-netty-5.15.0.jar:5.15.0]

This looks like it is happening because of a transient dependency on com.networknt:json-schema-validator:1.0.76 in the org.mock-server library.

If we switch our Gradle dependencies to use the shaded MockServer jar, as in the following:

implementation("com.networknt:json-schema-validator:2.0.0")
...
testImplementation("org.mock-server:mockserver-netty-no-dependencies:5.15.0")

we get a different error:

java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key crossEdits
	at java.base/java.util.ResourceBundle.getObject(ResourceBundle.java:558)
	at java.base/java.util.ResourceBundle.getObject(ResourceBundle.java:552)
	at java.base/java.util.ResourceBundle.getString(ResourceBundle.java:514)
	at shaded_package.com.networknt.schema.I18nSupport.getString(I18nSupport.java:33)
	at shaded_package.com.networknt.schema.ValidatorTypeCode.<clinit>(ValidatorTypeCode.java:54)
	at shaded_package.com.networknt.schema.Version7.getInstance(Version7.java:18)
	at shaded_package.com.networknt.schema.JsonSchemaFactory.getInstance(JsonSchemaFactory.java:244)
	at org.mockserver.validator.jsonschema.JsonSchemaValidator.getJsonSchemaFactory(JsonSchemaValidator.java:90)

If we revert json-schema-validator to version 1.5.9 in the Gradle dependencies, the first configuration with mockserver-netty works correctly, but the shaded library configuration using mockserver-netty-no-dependencies still throws the resource bundle exception.

MockServer version
MockServer 5.15.0
Java 25.0.1
Gradle 9.2.1

To Reproduce
See explanation above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions