com.fasterxml.jackson.module.jsonSchema.JsonSchema类的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(13.9k)|赞(0)|评价(0)|浏览(234)

本文整理了Java中com.fasterxml.jackson.module.jsonSchema.JsonSchema类的一些代码示例,展示了JsonSchema类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonSchema类的具体详情如下:
包路径:com.fasterxml.jackson.module.jsonSchema.JsonSchema
类名称:JsonSchema

JsonSchema介绍

[英]The type wraps the json schema specification at : Json JsonSchema DraftJSON (JavaScript Object Notation) JsonSchema defines the media type "application/schema+json", a JSON based format for defining the structure of JSON data. JSON JsonSchema provides a contract for what JSON data is required for a given application and how to interact with it. JSON JsonSchema is intended to define validation, documentation, hyperlink navigation, and interaction control of JSON data. JSON (JavaScript Object Notation) JsonSchema is a JSON media type for defining the structure of JSON data. JSON JsonSchema provides a contract for what JSON data is required for a given application and how to interact with it. JSON JsonSchema is intended to define validation, documentation, hyperlink navigation, and interaction control of JSON data. An example JSON JsonSchema provided by the JsonSchema draft:

{ 
"name":"Product", 
"properties":{ 
"id":{ 
"type":"number", 
"description":"Product identifier", 
"required":true 
}, 
"name":{ 
"description":"Name of the product", 
"type":"string", 
"required":true 
}, 
"price":{ 
"required":true, 
"type": "number", 
"minimum":0, 
"required":true 
}, 
"tags":{ 
"type":"array", 
"items":{ 
"type":"string" 
} 
} 
}, 
"links":[ 
{ 
"rel":"full", 
"href":"{id}" 
}, 
{ 
"rel":"comments", 
"href":"comments/?id={id}" 
} 
] 
}

[中]该类型将json模式规范包装在:Json JsonSchema Draftjson(JavaScript对象表示法)JsonSchema定义了媒体类型“application/schema+json”,这是一种基于json的格式,用于定义json数据的结构。JSON JsonSchema为给定应用程序需要哪些JSON数据以及如何与之交互提供了一个约定。JSON JsonSchema旨在定义JSON数据的验证、文档、超链接导航和交互控制。JSON(JavaScript对象表示法)JsonSchema是一种JSON媒体类型,用于定义JSON数据的结构。JSON JsonSchema为给定应用程序需要哪些JSON数据以及如何与之交互提供了一个约定。JSON JsonSchema旨在定义JSON数据的验证、文档、超链接导航和交互控制。JsonSchema草稿提供的JSON JsonSchema示例:

{ 
"name":"Product", 
"properties":{ 
"id":{ 
"type":"number", 
"description":"Product identifier", 
"required":true 
}, 
"name":{ 
"description":"Name of the product", 
"type":"string", 
"required":true 
}, 
"price":{ 
"required":true, 
"type": "number", 
"minimum":0, 
"required":true 
}, 
"tags":{ 
"type":"array", 
"items":{ 
"type":"string" 
} 
} 
}, 
"links":[ 
{ 
"rel":"full", 
"href":"{id}" 
}, 
{ 
"rel":"comments", 
"href":"comments/?id={id}" 
} 
] 
}

代码示例

代码示例来源:origin: com.fasterxml.jackson.module/jackson-module-jsonSchema

protected boolean _equals(JsonSchema that)
  {
    return equals(getId(), getId())
        // 27-Apr-2015, tatu: Should not need to check type explicitly
//                 && equals(getType(), getType())
        && equals(getRequired(), that.getRequired())
        && equals(getReadonly(), that.getReadonly())
        && equals(get$ref(), that.get$ref())
        && equals(get$schema(), that.get$schema())
        && arraysEqual(getDisallow(), that.getDisallow())
        && arraysEqual(getExtends(), that.getExtends());
  }

代码示例来源:origin: com.github.terran4j/terran4j-commons-api2doc

public static ApiDataType toDataType(JsonSchema schema) {
  if (schema == null) {
    return null;
  }
  if (schema.isBooleanSchema()) {
    return ApiDataType.BOOLEAN;
  }
  if (schema.isIntegerSchema()) {
    return ApiDataType.INT;
  }
  if (schema.isStringSchema()) {
    return ApiDataType.STRING;
  }
  if (schema.isNumberSchema()) {
    return ApiDataType.NUMBER;
  }
  if (schema.isObjectSchema()) {
    return ApiDataType.OBJECT;
  }
  if (schema.isArraySchema()) {
    return ApiDataType.ARRAY;
  }
  return null;
}

代码示例来源:origin: com.fasterxml.jackson.module/jackson-module-jsonSchema

/**
   * Adds writes the type as the title of the schema.
   * 
   * @param schema The schema who's title to set.
   * @param type The type of the object represented by the schema.
   */
  private void addTitle(JsonSchema schema, JavaType type)
  {
    if (!schema.isSimpleTypeSchema()) {
      throw new RuntimeException("given non simple type schema: " + schema.getType());
    }
    schema.asSimpleTypeSchema().setTitle(type.getGenericSignature());
  }
}

代码示例来源:origin: com.fasterxml.jackson.module/jackson-module-jsonSchema

protected JsonSchema addValidationConstraints(JsonSchema schema, BeanProperty prop) {
  {
    Boolean required = constraintResolver.getRequired(prop);
    if (required != null) {
      schema.setRequired(required);
    }
  }
  if (schema.isArraySchema()) {
    ArraySchema arraySchema = schema.asArraySchema();
    arraySchema.setMaxItems(constraintResolver.getArrayMaxItems(prop));
    arraySchema.setMinItems(constraintResolver.getArrayMinItems(prop));
  } else if (schema.isNumberSchema()) {
    NumberSchema numberSchema = schema.asNumberSchema();
    numberSchema.setMaximum(constraintResolver.getNumberMaximum(prop));
    numberSchema.setMinimum(constraintResolver.getNumberMinimum(prop));
  } else if (schema.isStringSchema()) {
    StringSchema stringSchema = schema.asStringSchema();
    stringSchema.setMaxLength(constraintResolver.getStringMaxLength(prop));
    stringSchema.setMinLength(constraintResolver.getStringMinLength(prop));
    stringSchema.setPattern(constraintResolver.getStringPattern(prop));
  }
  return schema;
}

代码示例来源:origin: dremio/dremio-oss

String id = schema.getId();
if (id == null && schema instanceof ReferenceSchema) {
 id = schema.get$ref();
 return;
if (schema.isObjectSchema()) {
 followed.add(id);
 objectExample(sb, maxlength, indent, schema, refs, followed, referenced, id);
} else if (schema.isArraySchema()) {
 arrayExample(sb, maxlength, indent, schema, refs, followed, referenced);
} else if (schema instanceof ReferenceSchema) {
 if (refs.containsKey(schema.get$ref())) {
  example(sb, maxlength, indent, refs.get(schema.get$ref()), refs, followed, referenced);
 } else {
  sb.append(refExample(schema.get$ref()));

代码示例来源:origin: dremio/dremio-oss

private void findRefs(JsonSchema schema, Map<String, JsonSchema> refs, Set<String> referenced) {
 addRef(schema, refs);
 if (schema instanceof ReferenceSchema) {
  referenced.add(schema.get$ref());
 } else if (schema.isArraySchema()) {
  ArraySchema as = schema.asArraySchema();
  if (as.getItems() != null) {
   if (as.getItems().isSingleItems()) {
    findRefs(as.getItems().asSingleItems().getSchema(), refs, referenced);
   } else if (as.getItems().isArrayItems()) {
    ArrayItems items = as.getItems().asArrayItems();
    for (JsonSchema item : items.getJsonSchemas()) {
     findRefs(item, refs, referenced);
    }
   } else {
    throw new UnsupportedOperationException(as.getItems().toString());
   }
  }
 } else if (schema.isObjectSchema()) {
  ObjectSchema os = schema.asObjectSchema();
  for (JsonSchema value : os.getProperties().values()) {
   findRefs(value, refs, referenced);
  }
 }
}

代码示例来源:origin: com.intel.icecp/icecp-core

String ref;
switch (ft = pSchema.getType()) {
  case OBJECT:
    pObject = createNewInstance(objectClass);
    ObjectSchema objSchema = pSchema.asObjectSchema();
    for (Entry<String, JsonSchema> obj : objSchema.getProperties().entrySet()) {
      String key = obj.getKey();
    ArraySchema arrSchema = pSchema.asArraySchema();
    Integer entries;
    if (arrSchema.getMinItems() != null && arrSchema.getMinItems().equals(entries = arrSchema.getMaxItems())) {
      if (items.isSingleItems()) {
        if (items.asSingleItems().getSchema().get$ref() == null) {
          items.asSingleItems().getSchema().set$ref(arrSchema.get$ref());
    ref = pSchema.get$ref();
    fmt = pSchema.asIntegerSchema().getFormat();
    ref = pSchema.get$ref();
    if (ref != null && ref.toLowerCase().equals(REF$_DOUBLE)) {
      pObject = readDoubleData(objectClass, arrayElements);

代码示例来源:origin: dremio/dremio-oss

private void addRef(JsonSchema schema, Map<String, JsonSchema> refs) {
 if (schema.getId() != null && !refs.containsKey(schema.getId())) {
  refs.put(schema.getId(), schema);
 }
}

代码示例来源:origin: io.syndesis/inspector

/* default */ static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) {
  for (final Entry<String, JsonSchema> entry : properties.entrySet()) {
    final JsonSchema subschema = entry.getValue();
    String path;
    final String key = entry.getKey();
    if (context == null) {
      path = key;
    } else {
      path = context + "." + key;
    }
    if (subschema.isValueTypeSchema()) {
      paths.add(path);
    } else if (subschema.isObjectSchema()) {
      fetchPaths(path, paths, ((ObjectSchema) subschema).getProperties());
    }
  }
}

代码示例来源:origin: dremio/dremio-oss

private String primitiveTypeExample(JsonSchema schema) {
 switch (schema.getType()) {
 case ANY:
  return "any";
  return "{ ... }";
 case STRING:
  Set<String> enums = schema.asStringSchema().getEnums();
  if (enums != null && !enums.isEmpty()) {
   List<String> quoted = new ArrayList<>();
  return "? " + schema.getType();

代码示例来源:origin: com.fasterxml.jackson.module/jackson-module-jsonSchema

@Override
public String idFromValue(Object value) {
  if (value instanceof JsonSchema) {
    return ((JsonSchema)value).getType().value();
  }
  return null;
}

代码示例来源:origin: com.fasterxml.jackson.module/jackson-module-jsonSchema

protected static <T> boolean arraysEqual(T[] arr1, T[] arr2) {
     if (arr1 == null) {
       return arr2 == null;
     }
     if (arr2 == null) {
       return false;
     }
     int len = arr1.length;
     if (len != arr2.length) {
       return false;
     }
     for (int i = 0; i < len; ++i) {
       T ob1 = arr1[i];
       T ob2 = arr2[i];

       if (!equals(ob1, ob2)) {
         return false;
       }
     }
     return true;
   }
}

代码示例来源:origin: dremio/dremio-oss

private void arrayExample(StringBuilder sb, int maxlength, String indent, JsonSchema schema,
  Map<String, JsonSchema> refs, Set<String> followed, Set<String> referenced) {
 sb.append("[\n").append(indent).append("  ");
 ArraySchema as = schema.asArraySchema();
 if (as.getItems() == null) {
  sb.append(" ... ]");
 } else if (as.getItems().isSingleItems()) {
  example(sb, maxlength, indent + "  ", as.getItems().asSingleItems().getSchema(), refs, followed, referenced);
  sb.append(",\n").append(indent).append("  ...\n").append(indent).append("]");
 } else if (as.getItems().isArrayItems()) {
  ArrayItems items = as.getItems().asArrayItems();
  for (JsonSchema item : items.getJsonSchemas()) {
   sb.append("\n").append(indent);
   example(sb, maxlength, indent + "  ", item, refs, followed, referenced);
   sb.append(",");
  }
  sb.append("]");
 } else {
  throw new UnsupportedOperationException(as.getItems().toString());
 }
}

代码示例来源:origin: dremio/dremio-oss

private void objectExample(StringBuilder sb, int maxlength, String indent, JsonSchema schema,
  Map<String, JsonSchema> refs, Set<String> followed, Set<String> referenced, String id) {
 sb.append("{");
 if (referenced.contains(id)) {
  shortId(sb, schema);
 }
 ObjectSchema os = schema.asObjectSchema();
 if (os.getProperties().isEmpty()) {
  AdditionalProperties additionalProperties = os.getAdditionalProperties();
  if (additionalProperties instanceof SchemaAdditionalProperties) {
   sb.append("\n").append(indent).append("  ").append("abc").append(": ");
   example(sb, maxlength, indent + "  ", ((SchemaAdditionalProperties) additionalProperties).getJsonSchema(), refs, followed, referenced);
   sb.append(", ...");
  }
 }
 Map<String, JsonSchema> props = new TreeMap<>(os.getProperties());
 for (Entry<String, JsonSchema> entry : props.entrySet()) {
  sb.append("\n").append(indent).append("  ").append(entry.getKey()).append(": ");
  example(sb, maxlength, indent + "  ", entry.getValue(), refs, followed, referenced);
  sb.append(",");
 }
 sb.append("\n").append(indent).append("}");
}

代码示例来源:origin: FasterXML/jackson-module-jsonSchema

protected JsonSchema addValidationConstraints(JsonSchema schema, BeanProperty prop) {
  {
    Boolean required = constraintResolver.getRequired(prop);
    if (required != null) {
      schema.setRequired(required);
    }
  }
  if (schema.isArraySchema()) {
    ArraySchema arraySchema = schema.asArraySchema();
    arraySchema.setMaxItems(constraintResolver.getArrayMaxItems(prop));
    arraySchema.setMinItems(constraintResolver.getArrayMinItems(prop));
  } else if (schema.isNumberSchema()) {
    NumberSchema numberSchema = schema.asNumberSchema();
    numberSchema.setMaximum(constraintResolver.getNumberMaximum(prop));
    numberSchema.setMinimum(constraintResolver.getNumberMinimum(prop));
  } else if (schema.isStringSchema()) {
    StringSchema stringSchema = schema.asStringSchema();
    stringSchema.setMaxLength(constraintResolver.getStringMaxLength(prop));
    stringSchema.setMinLength(constraintResolver.getStringMinLength(prop));
    stringSchema.setPattern(constraintResolver.getStringPattern(prop));
  }
  return schema;
}

代码示例来源:origin: dremio/dremio-oss

private void shortId(StringBuilder sb, JsonSchema s) {
 if (s.getId() != null) {
  sb.append(" /** ").append(shortId(s.getId())).append(" **/");
 }
}

代码示例来源:origin: io.syndesis.rest/rest-inspector

static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) {
  for (final Entry<String, JsonSchema> entry : properties.entrySet()) {
    final JsonSchema subschema = entry.getValue();
    String path;
    final String key = entry.getKey();
    if (context == null) {
      path = key;
    } else {
      path = context + "." + key;
    }
    if (subschema.isValueTypeSchema()) {
      paths.add(path);
    } else if (subschema.isObjectSchema()) {
      fetchPaths(path, paths, ((ObjectSchema) subschema).getProperties());
    }
  }
}

代码示例来源:origin: FasterXML/jackson-module-jsonSchema

@Override
public String idFromValue(Object value) {
  if (value instanceof JsonSchema) {
    return ((JsonSchema)value).getType().value();
  }
  return null;
}

代码示例来源:origin: FasterXML/jackson-module-jsonSchema

protected static <T> boolean arraysEqual(T[] arr1, T[] arr2) {
     if (arr1 == null) {
       return arr2 == null;
     }
     if (arr2 == null) {
       return false;
     }
     int len = arr1.length;
     if (len != arr2.length) {
       return false;
     }
     for (int i = 0; i < len; ++i) {
       T ob1 = arr1[i];
       T ob2 = arr2[i];

       if (!equals(ob1, ob2)) {
         return false;
       }
     }
     return true;
   }
}

代码示例来源:origin: FasterXML/jackson-module-jsonSchema

protected boolean _equals(JsonSchema that)
  {
    return equals(getId(), getId())
        // 27-Apr-2015, tatu: Should not need to check type explicitly
//                 && equals(getType(), getType())
        && equals(getRequired(), that.getRequired())
        && equals(getReadonly(), that.getReadonly())
        && equals(get$ref(), that.get$ref())
        && equals(get$schema(), that.get$schema())
        && arraysEqual(getDisallow(), that.getDisallow())
        && arraysEqual(getExtends(), that.getExtends());
  }

相关文章