use of io.atlasmap.json.v2.JsonInspectionResponse in project atlasmap by atlasmap.
the class JsonService method inspect.
/**
* Inspect a JSON schema or instance and return a Document object.
* @param requestIn request
* @return {@link JsonInspectionResponse}
*/
@POST
@Path("/inspect")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Inspect JSON", description = "Inspect a JSON schema or instance and return a Document object")
@RequestBody(description = "JsonInspectionRequest object", content = @Content(schema = @Schema(implementation = JsonInspectionRequest.class)))
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = JsonInspectionResponse.class)), description = "Return a Document object represented by JsonDocument"))
public Response inspect(InputStream requestIn) {
JsonInspectionRequest request = fromJson(requestIn, JsonInspectionRequest.class);
long startTime = System.currentTimeMillis();
JsonInspectionResponse response = new JsonInspectionResponse();
JsonDocument d = null;
try {
if (request.getType() == null || request.getJsonData() == null) {
response.setErrorMessage("Json data and Instance or Schema inspection type must be specified in request");
} else {
JsonInspectionService s = new JsonInspectionService();
String jsonData = cleanJsonData(request.getJsonData());
if (!validJsonData(jsonData)) {
response.setErrorMessage("Invalid json payload specified");
} else {
switch(request.getType()) {
case INSTANCE:
d = s.inspectJsonDocument(jsonData);
break;
case SCHEMA:
d = s.inspectJsonSchema(jsonData);
break;
default:
response.setErrorMessage("Unsupported inspection type: " + request.getType());
break;
}
}
}
} catch (Exception e) {
LOG.error("Error inspecting json: " + e.getMessage(), e);
response.setErrorMessage(e.getMessage());
} finally {
response.setExecutionTime(System.currentTimeMillis() - startTime);
}
AtlasUtil.excludeNotRequestedFields(d, request.getInspectPaths());
response.setJsonDocument(d);
return Response.ok().entity(toJson(response)).build();
}
Aggregations