3 回答
TA贡献1805条经验 获得超9个赞
为我们做以下工作,在 pom.xml 中,我们排除了这两个定义它们自己的类 org.json.JSONObject 的依赖项: com.unboundid.components:json和com.unboundid.components:mimepull。IE:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>org.jvnet.mimepull</groupId>
<artifactId>mimepull</artifactId>
</exclusion>
</exclusions>
<version>${spring.boot.version}</version>
</dependency>
TA贡献1886条经验 获得超2个赞
或者,您也可以将 XML 转换为 JSON,然后可以根据 JSON 模式验证 JSON。
依赖:
<dependency>
<groupId>com.github.fge</groupId>
<artifactId>json-schema-validator</artifactId>
<version>2.2.6</version>
</dependency>
代码:
JsonNode node = JsonLoader.fromString(builder.toString());
JsonNode data = JsonLoader.fromString(serviceCreateJson.trim());
JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
JsonSchema sch = factory.getJsonSchema(node);
ProcessingReport report = sch.validate(data);
boolean isSuccess = report.isSuccess();
添加回答
举报