You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

org.everit.json.schema.SchemaException无法确定Schema版本问题问询

org.everit.json.schema 抛could not determine version异常排查

触发原因及解决方案

  • 核心原因:库版本不兼容

    org.everit.json.schema所有正式发行版本最高仅支持到JSON Schema Draft 7,无法识别你声明的Draft 2020-12版本,所以即使$schema字段存在也会抛出版本识别异常。
    直接修改Schema中的$schema字段为Draft 7的声明即可解决:
    "$schema": "http://json-schema.org/draft-07/schema#"
    
  • 次要排查点:加载流程异常

    你的现有代码存在两处可能导致Schema内容异常的问题:
    1. 路径拼接缺少分隔符,可能导致读取到错误的/空的Schema文件,建议修改路径拼接逻辑:
      String schemaPath = new File("").getAbsolutePath() + File.separator + "schema.json";
      
    2. 先通过json-simple解析、再转字符串构造org.json.JSONObject的多余序列化/反序列化步骤,可能出现字段丢失问题,可直接用org.json的API读取文件,避免多余转换:
      import java.nio.charset.StandardCharsets;
      import java.nio.file.Files;
      import java.nio.file.Paths;
      import org.json.JSONObject;
      import org.everit.json.schema.Schema;
      import org.everit.json.schema.loader.SchemaLoader;
      
      // 优化后的加载逻辑
      String schemaPath = new File("").getAbsolutePath() + File.separator + "schema.json";
      String schemaContent = new String(Files.readAllBytes(Paths.get(schemaPath)), StandardCharsets.UTF_8);
      JSONObject rawSchema = new JSONObject(schemaContent);
      Schema schema = SchemaLoader.load(rawSchema);
      
  • 特殊场景解决方案

    如果必须使用Draft 2020-12版本的Schema特性,需要更换支持更高版本的JSON Schema校验库,比如networknt的json-schema-validator。

内容的提问来源于stack exchange,提问作者Software Guy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 07:27:03