mockserver icon indicating copy to clipboard operation
mockserver copied to clipboard

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

Open peter-thomas-mgd opened this issue 1 year ago • 4 comments

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.

peter-thomas-mgd avatar Nov 19 '25 18:11 peter-thomas-mgd

The same issue with org.mock-server:mockserver-netty-no-dependencies:5.15.0. As a work around I have cloned jsv-messages.properties from com.networknt:json-schema-validator:2.0.0 into my project resource bundle and added the missed keys from com.networknt:json-schema-validator:1.0.76:

crossEdits = {0}: has an error with 'cross edits'
dateTime = {0}: {1} is an invalid {2}
edits = {0}: has an error with 'edits'
uuid = {0}: {1} is an invalid {2}

It works.

anatoly-spb avatar Mar 26 '26 10:03 anatoly-spb

Closing — this is a classpath conflict, not a MockServer bug.

MockServer 5.15.0 depends on com.networknt:json-schema-validator:1.0.73 which uses the com.networknt.schema.SpecVersion$VersionFlag API. Version 2.0.0 of json-schema-validator introduced breaking changes (package renames, API changes) that are incompatible with MockServer's usage.

This is expected behavior when a library on the classpath has a major version bump with breaking API changes. MockServer's shaded JAR (mockserver-netty-no-dependencies) bundles its own copy of json-schema-validator to avoid exactly this kind of conflict.

Solutions:

  1. Use the mockserver-netty-no-dependencies artifact instead of mockserver-netty — it shades all dependencies to avoid classpath conflicts
  2. Use Gradle's dependency resolution strategy to force the version MockServer needs:
    configurations.all {
        resolutionStrategy {
            force 'com.networknt:json-schema-validator:1.0.73'
        }
    }
    
  3. Keep json-schema-validator at 1.x in your project until MockServer upgrades its dependency

MockServer cannot upgrade to json-schema-validator 2.x because it requires Java 17+, which would break MockServer's Java 11 compatibility requirement.

jamesdbloom avatar May 08 '26 13:05 jamesdbloom

Solution #1 won’t work. That was part of the motivation for opening the ticket in the first place. You seem to have missed the part in the ticket description that describes another error that occurs when the shaded library is used.

We ended up solving the problem by replacing mockserver with a different library.

peter-thomas-mgd avatar May 08 '26 13:05 peter-thomas-mgd

@jamesdbloom the root cause of the problem is resource bundle. it cannot be resolved with -no-dependencies approach, because -no-dependencies cannot influence on message resource bundle search process: see my previous anwser.

anatoly-spb avatar May 08 '26 13:05 anatoly-spb