本文整理了Java中io.swagger.v3.core.util.Json
类的一些代码示例,展示了Json
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json
类的具体详情如下:
包路径:io.swagger.v3.core.util.Json
类名称:Json
暂无
代码示例来源:origin: swagger-api/swagger-core
default OpenAPIConfiguration deserializeConfig(String path, String configAsString) {
try {
if (path.toLowerCase().endsWith("json")) {
return Json.mapper().readValue(configAsString, SwaggerConfiguration.class);
} else { // assume yaml
return Yaml.mapper().readValue(configAsString, SwaggerConfiguration.class);
}
} catch (Exception e) {
LOGGER.error("exception reading config: " + e.getMessage(), e);
return null;
}
}
代码示例来源:origin: swagger-api/swagger-core
public static OpenAPIConfiguration deepCopy(OpenAPIConfiguration config) {
if (config == null) {
return null;
}
try {
return Json.mapper().readValue(Json.pretty(config), SwaggerConfiguration.class);
} catch (Exception e) {
LOGGER.error("Exception cloning config: " + e.getMessage(), e);
return config;
}
}
代码示例来源:origin: swagger-api/swagger-core
@Override
public void run() {
Json.prettyPrint(swagger);
}
});
代码示例来源:origin: swagger-api/swagger-core
public static String pretty(Object o) {
try {
return pretty().writeValueAsString(o);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
代码示例来源:origin: swagger-api/swagger-core
final String swaggerJson = Json.mapper().writeValueAsString(swagger);
Json.prettyPrint(swagger);
final OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
SerializationMatchers.assertEqualsToJson(rebuilt, swaggerJson);
代码示例来源:origin: swagger-api/swagger-core
public static void prettyPrint(Object o) {
try {
System.out.println(pretty().writeValueAsString(o).replace("\r", ""));
} catch (Exception e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: swagger-api/swagger-core
public ModelConverters() {
converters = new CopyOnWriteArrayList<>();
converters.add(new ModelResolver(Json.mapper()));
}
代码示例来源:origin: swagger-api/swagger-core
if (mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE)) {
if (prettyPrint) {
out.write(Json.pretty().writeValueAsBytes(data));
} else {
out.write(Json.mapper().writeValueAsBytes(data));
headers.add("Content-Type", "application/json");
if (prettyPrint) {
out.write(Json.pretty().writeValueAsBytes(data));
} else {
out.write(Json.mapper().writeValueAsBytes(data));
代码示例来源:origin: swagger-api/swagger-core
@Override
public void run() {
try {
Thread[] thds = new Thread[tg.activeCount()];
tg.enumerate(thds);
for (Thread t : thds) {
if (t != null) {
t.join(10000);
}
}
} catch (Exception e) {
e.printStackTrace();
}
for (OpenAPI filtered : filteredMap.values()) {
assertEquals(Json.pretty(openAPI), Json.pretty(filtered));
}
}
}
代码示例来源:origin: swagger-api/swagger-core
@Override
public void run() {
Json.prettyPrint(new ThrowHelper());
}
});
代码示例来源:origin: swagger-api/swagger-core
public static ObjectWriter pretty() {
return mapper().writer(new DefaultPrettyPrinter());
}
代码示例来源:origin: swagger-api/swagger-core
private void handleUnwrapped(List<Schema> props, Schema innerModel, String prefix, String suffix) {
if (StringUtils.isBlank(suffix) && StringUtils.isBlank(prefix)) {
if (innerModel.getProperties() != null) {
props.addAll(innerModel.getProperties().values());
}
} else {
if (prefix == null) {
prefix = "";
}
if (suffix == null) {
suffix = "";
}
if (innerModel.getProperties() != null) {
for (Schema prop : (Collection<Schema>) innerModel.getProperties().values()) {
try {
Schema clonedProp = Json.mapper().readValue(Json.pretty(prop), Schema.class);
clonedProp.setName(prefix + prop.getName() + suffix);
props.add(clonedProp);
} catch (IOException e) {
LOGGER.error("Exception cloning property", e);
return;
}
}
}
}
}
代码示例来源:origin: swagger-api/swagger-core
@Override
public void run() {
Json.pretty(new ThrowHelper());
}
});
代码示例来源:origin: swagger-api/swagger-core
private void compareAsJson(Class<?> cls, String fileName) throws IOException {
final Map<String, Schema> schemas = ModelConverters.getInstance().readAll(cls);
Json.prettyPrint(schemas);
final String json = ResourceUtils.loadClassResource(getClass(), fileName);
SerializationMatchers.assertEqualsToJson(schemas, json);
}
}
代码示例来源:origin: swagger-api/swagger-core
protected GericModelConverter() {
super(Json.mapper());
}
代码示例来源:origin: swagger-api/swagger-core
resp.setContentType(APPLICATION_JSON);
PrintWriter pw = resp.getWriter();
pw.write(pretty ? Json.pretty(oas) : Json.mapper().writeValueAsString(oas));
pw.close();
代码示例来源:origin: swagger-api/swagger-core
@Test(description = "it should clone everything")
public void cloneEverything() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoOpOperationsFilter(), null, null, null);
assertEquals(Json.pretty(filtered), Json.pretty(openAPI));
}
代码示例来源:origin: swagger-api/swagger-core
Json.prettyPrint(models);
SerializationMatchers.assertEqualsToJson(models, json);
代码示例来源:origin: swagger-api/swagger-core
private Schema deserializeObjectSchema(JsonNode node) {
JsonNode additionalProperties = node.get("additionalProperties");
Schema schema = null;
if (additionalProperties != null) {
// try first to convert to Schema, if it fails it must be a boolean
try {
Schema innerSchema = Json.mapper().convertValue(additionalProperties, Schema.class);
((ObjectNode)node).remove("additionalProperties");
MapSchema ms = Json.mapper().convertValue(node, MapSchema.class);
ms.setAdditionalProperties(innerSchema);
schema = ms;
} catch (Exception e) {
schema = Json.mapper().convertValue(node, ObjectSchema.class);
Boolean additionalPropsBoolean = Json.mapper().convertValue(additionalProperties, Boolean.class);
schema.setAdditionalProperties(additionalPropsBoolean);
}
} else {
schema = Json.mapper().convertValue(node, ObjectSchema.class);
}
return schema;
}
}
代码示例来源:origin: swagger-api/swagger-core
Schema clonedModel = Json.mapper().readValue(Json.pretty(definition), Schema.class);
if (clonedModel.getProperties() != null) {
clonedModel.getProperties().clear();
内容来源于网络,如有侵权,请联系作者删除!