|
|
@@ -606,14 +606,6 @@ public class DefaultExamSprintReportApplicationService implements ExamSprintRepo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private JsonNode requireObjectField(JsonNode objectNode, String fieldName) {
|
|
|
- JsonNode field = objectNode.get(fieldName);
|
|
|
- if (field == null || !field.isObject()) {
|
|
|
- throw validationException(ACHIEVEMENT_REPORT_NAME, "字段 " + fieldName + " 必须为对象");
|
|
|
- }
|
|
|
- return field;
|
|
|
- }
|
|
|
-
|
|
|
private void requireOptionalBooleanField(JsonNode objectNode, String fieldName) {
|
|
|
JsonNode field = objectNode.get(fieldName);
|
|
|
if (field != null && !field.isNull() && !field.isBoolean()) {
|
|
|
@@ -646,29 +638,11 @@ public class DefaultExamSprintReportApplicationService implements ExamSprintRepo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void requireTextualArrayField(JsonNode objectNode, String fieldPath) {
|
|
|
- JsonNode field = objectNode.get(leafFieldName(fieldPath));
|
|
|
- if (field == null || !field.isArray()) {
|
|
|
- throw validationException(ACHIEVEMENT_REPORT_NAME, "字段 " + fieldPath + " 必须为字符串数组");
|
|
|
- }
|
|
|
- int index = 0;
|
|
|
- for (JsonNode element : field) {
|
|
|
- if (!element.isTextual()) {
|
|
|
- throw validationException(ACHIEVEMENT_REPORT_NAME, "字段 " + fieldPath + "[" + index + "] 必须为字符串");
|
|
|
- }
|
|
|
- index++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private <T> T readPayload(JsonNode payload, Class<T> payloadType, String reportName) {
|
|
|
requireObjectPayload(payload, reportName);
|
|
|
|
|
|
try {
|
|
|
- T reportPayload = objectMapper.treeToValue(payload, payloadType);
|
|
|
- if (reportPayload == null) {
|
|
|
- throw validationException(reportName, "payload 不能为空");
|
|
|
- }
|
|
|
- return reportPayload;
|
|
|
+ return objectMapper.treeToValue(payload, payloadType);
|
|
|
} catch (JsonProcessingException | IllegalArgumentException exception) {
|
|
|
throw validationException(reportName, "payload 无法解析为报告请求结构,请检查字段类型和结构");
|
|
|
}
|