jsonschema.core.exceptions.InvalidSchemaException:致命:core.invalidSchema 等级:"fatal"

jsonschema.core.exceptions.InvalidSchemaException: fatal: core.invalidSchema level: "fatal"

我的架构是:

{
    "title": "Order",
    "description": "An order from oms",
    "type": "object",
    "properties": {
        "order_id": {
            "description": "The unique identifier for an order",
            "type": "number"
        },
        "order_bill_from_party_id": {
            "description": "The unique identifier for a party",
            "type": "string"
        },
        "test":{
         "type":"integer"
        }
    },
    "required": ["order_id"]
}

我的输入是:

{"order_bill_from_party_id":"abc",
"order_id":1234}

我的验证码:

    val factory : JsonSchemaFactory= JsonSchemaFactory.byDefault()
    val validator: JsonValidator = factory.getValidator
    val schemaJson: JsonNode = JsonNodeFactory.instance.textNode(schema)
    val inputJson = JsonNodeFactory.instance.textNode(input)
    println(schemaJson)
    val report: ProcessingReport = validator.validate(schemaJson, inputJson)

编辑: schemaJson 采用以下形式:

 {\n  
  \"title\": \"Order\",\n   
  \"description\": \"An order from oms\",\n  
  \"type\": \"object\",\n   
 \"properties\": {\n     
   \"order_id\": {\n        
    \"description\": \"The unique identifier for an order\",\n    
        \"type\": \"number\"\n     
   },\n     
   \"order_bill_from_party_id\": {\n  
     \"description\": \"The unique identifier for a party\",\n            
      \"type\": \"string\"\n 
       },\n      
  \"test\":{\n   
      \"type\":\"integer\"\n   
     }\n  
  },\n  
  \"required\": [\"order_id\"]\n
}

但是我遇到了一个例外:

org.specs.runner.SpecError: com.github.fge.jsonschema.core.exceptions.InvalidSchemaException: fatal: core.invalidSchema
    level: "fatal"
org.specs.runner.UserError: com.github.fge.jsonschema.core.exceptions.InvalidSchemaException: fatal: core.invalidSchema
    level: "fatal"

    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:86)
    at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:48)
    at com.github.fge.jsonschema.core.processing.ProcessingResult.of(ProcessingResult.java:78)
    at com.github.fge.jsonschema.main.JsonValidator.validate(JsonValidator.java:103)
    at com.github.fge.jsonschema.main.JsonValidator.validate(JsonValidator.java:123)
    at com.flipkart.marketing.bro.core.ValidationSchema.validate(ValidationSchema.scala:25)
    at com.flipkart.marketing.bro.core.ValidationSchemaTest$$anonfun$$anonfun$apply.apply$mcV$sp(ValidationSchemaTest.scala:29)
    at com.flipkart.marketing.bro.core.ValidationSchemaTest$$anonfun$$anonfun$apply.apply(ValidationSchemaTest.scala:27)
    at com.flipkart.marketing.bro.core.ValidationSchemaTest$$anonfun$$anonfun$apply.apply(ValidationSchemaTest.scala:27)
    at org.specs.specification.LifeCycle$class.withCurrent(ExampleLifeCycle.scala:66)
    at org.specs.specification.Examples.withCurrent(Examples.scala:52)

但是在 :

上进行测试
http://json-schema-validator.herokuapp.com/

我得到一个

`success 
 []`.

有人可以帮帮我吗?测试站点暗示我的模式是正确的,但我的代码给出了例外。我认为这是因为转义字符。我该如何解决这个问题并删除 JsonNode 中的转义字符? 提前致谢!

使用 JsonLoader.fromString 而不是 JsonNodeFactory.instance.textNode 来加载您的架构和实例:

val schemaJson= JsonLoader.fromString(schema)
val inputJson = JsonLoader.fromString(input)

textNode 构造一个包含文本值的单个节点,这不是您想要的。