2014-07-07 101 views
1

需要用於用戶輸入的JSON模式驗證程序。我打算用https://github.com/fge/json-schema-validatorJSON模式驗證程序未加載

這裏是我想要做的事:

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模式驗證器期望在傑克遜的東西不可用。 但是想知道您是否遇到過您已經使用並解決它的版本的問題。

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

回答

2

通過升級傑克遜版本2.3.2

固定