7
我有一個JacksonMappingException
我使用產生的用戶錯誤:我可以自定義傑克遜錯誤信息嗎?
public Map<String, List<Map<String, String>>> getErrors(JsonMappingException e) {
Map<String, List<Map<String, String>>> errors = new HashMap<>();
List<Map<String, String>> badFields = new ArrayList<>();
for (Reference ref: e.getPath()) {
Map<String, String> badField = new HashMap<>();
badField.put("field", ref.getFieldName());
badField.put("description", e.getOriginalMessage());
badFields.add(badField);
}
errors.put("errors", badFields);
return errors;
}
這是除了錯誤的一些類極大,某些技術細節泄露給用戶,如階級結構等等,這是完全不合時宜:
{
"errors" : [ {
"field" : "id",
"description" : "Unrecognized field \"id\" (class motif.web.resource.UserResource$PutUser), not marked as ignorable"
} ]
}
我如何能有description
更像Unrecognized field \"id\"
沒有所有的技術魔神?