JSON Schema验证器未加载

时间:2014-07-07 05:25:14

标签: json validation jsonschema

需要用户输入的JSON模式验证程序。我计划使用https://github.com/fge/json-schema-validator

以下是我要做的事情:

static JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
static {
        try {
            logger.info("Looking for schema");

            JsonSchema schema = factory.getJsonSchema(JSONValidator.class
                    .getClassLoader()
                    .getResource("schema.json")
                    .toString());


        } catch (ProcessingException e) {
            logger.error("Failed to parse JSON Schema. Cannot validate JSON inputs ", e);
        }
    }

甚至在读取模式文件之前获取此异常。通过删除所有代码并仅保留此行来测试它:

static JsonSchemaFactory factory = JsonSchemaFactory.byDefault();

可能出现什么问题?

java.lang.NoSuchFieldError: WRITE_BIGDECIMAL_AS_PLAIN
    at com.github.fge.jackson.JacksonUtils.newMapper(JacksonUtils.java:155)
    at com.github.fge.jackson.JacksonUtils.<clinit>(JacksonUtils.java:55)
    at com.github.fge.jackson.JsonNodeReader.<init>(JsonNodeReader.java:82)
    at com.github.fge.jackson.JsonLoader.<clinit>(JsonLoader.java:50)
    at com.github.fge.jsonschema.SchemaVersion.<init>(SchemaVersion.java:63)
    at com.github.fge.jsonschema.SchemaVersion.<clinit>(SchemaVersion.java:44)
    at com.github.fge.jsonschema.core.load.configuration.LoadingConfigurationBuilder.<init>(LoadingConfigurationBuilder.java:117)
    at com.github.fge.jsonschema.core.load.configuration.LoadingConfiguration.byDefault(LoadingConfiguration.java:151)
    at com.github.fge.jsonschema.main.JsonSchemaFactoryBuilder.<init>(JsonSchemaFactoryBuilder.java:67)
    at com.github.fge.jsonschema.main.JsonSchemaFactory.newBuilder(JsonSchemaFactory.java:123)
    at com.github.fge.jsonschema.main.JsonSchemaFactory.byDefault(JsonSchemaFactory.java:113)
    at com.intuit.mumble.validator.JSONValidator.<clinit>(JSONValidator.java:29)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

我知道这个JSON Schema Validator在Jackson中所期待的东西是不可用的。 但是想知道您是否使用过您已经使用过的版本并且已经解决了这个问题。

json.schema.validator.version 2.2.5 jackson2.version 2.1.0

1 个答案:

答案 0 :(得分:2)

通过将jackson版本升级到2.3.2

来修复